Skip to content

Commit 0856c3a

Browse files
authored
Rollup merge of rust-lang#82315 - jsha:font-display-swap, r=GuillaumeGomez
Improve page load performance in rustdoc Add an explicit height to icons (which already had an explicit width) to allow browsers to lay out the page more accurately before the icons have been loaded. https://web.dev/optimize-cls/. Add min-width: 115px to the crate search dropdown. When the HTML first loads, this dropdown includes only the text "All crates." Later, JS loads the items underneath it, some of which are wider. That causes the dropdown to get wider, causing a distracting reflow. This sets a min-width based on the size that the dropdown eventually becomes based on the crates on doc.rust-lang.org, reducing page movement during load. Add font-display: swap. Per https://web.dev/font-display/, this prevents "flash of invisible text" during load by using a system font until the custom font is available. I've noticed this flash of invisible text occasionally when reading Rust docs. Note that users without cached fonts will see text, and then see it reflow. For `docs.rust-lang.org`, [setting caching headers will help a lot](rust-lang/simpleinfra#62). Generated output at https://jacob.hoffman-andrews.com/rust/flow-improvements/std/string/struct.String.html.
2 parents 22f5255 + f9cfe15 commit 0856c3a

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/doc/rust.css

+6
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,35 @@
33
font-style: normal;
44
font-weight: 400;
55
src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff');
6+
font-display: swap;
67
}
78
@font-face {
89
font-family: 'Fira Sans';
910
font-style: normal;
1011
font-weight: 500;
1112
src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff');
13+
font-display: swap;
1214
}
1315
@font-face {
1416
font-family: 'Source Serif Pro';
1517
font-style: normal;
1618
font-weight: 400;
1719
src: local('Source Serif Pro'), url("SourceSerifPro-Regular.ttf.woff") format('woff');
20+
font-display: swap;
1821
}
1922
@font-face {
2023
font-family: 'Source Serif Pro';
2124
font-style: italic;
2225
font-weight: 400;
2326
src: url("SourceSerifPro-It.ttf.woff") format('woff');
27+
font-display: swap;
2428
}
2529
@font-face {
2630
font-family: 'Source Serif Pro';
2731
font-style: normal;
2832
font-weight: 700;
2933
src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.ttf.woff") format('woff');
34+
font-display: swap;
3035
}
3136
@font-face {
3237
font-family: 'Source Code Pro';
@@ -35,6 +40,7 @@
3540
/* Avoid using locally installed font because bad versions are in circulation:
3641
* see https://github.com/rust-lang/rust/issues/24355 */
3742
src: url("SourceCodePro-Regular.woff") format('woff');
43+
font-display: swap;
3844
}
3945

4046
*:not(body) {

src/librustdoc/html/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ crate fn render<T: Print, S: Print>(
8383
<div class=\"theme-picker\">\
8484
<button id=\"theme-picker\" aria-label=\"Pick another theme!\" aria-haspopup=\"menu\">\
8585
<img src=\"{static_root_path}brush{suffix}.svg\" \
86-
width=\"18\" \
86+
width=\"18\" height=\"18\" \
8787
alt=\"Pick another theme!\">\
8888
</button>\
8989
<div id=\"theme-choices\" role=\"menu\"></div>\
@@ -103,7 +103,7 @@ crate fn render<T: Print, S: Print>(
103103
<button type=\"button\" class=\"help-button\">?</button>
104104
<a id=\"settings-menu\" href=\"{root_path}settings.html\">\
105105
<img src=\"{static_root_path}wheel{suffix}.svg\" \
106-
width=\"18\" \
106+
width=\"18\" height=\"18\" \
107107
alt=\"Change settings\">\
108108
</a>\
109109
</div>\

src/librustdoc/html/static/rustdoc.css

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
src: local('Fira Sans'),
77
url("FiraSans-Regular.woff2") format("woff2"),
88
url("FiraSans-Regular.woff") format('woff');
9+
font-display: swap;
910
}
1011
@font-face {
1112
font-family: 'Fira Sans';
@@ -14,6 +15,7 @@
1415
src: local('Fira Sans Medium'),
1516
url("FiraSans-Medium.woff2") format("woff2"),
1617
url("FiraSans-Medium.woff") format('woff');
18+
font-display: swap;
1719
}
1820

1921
/* See SourceSerifPro-LICENSE.txt for the Source Serif Pro license. */
@@ -22,18 +24,21 @@
2224
font-style: normal;
2325
font-weight: 400;
2426
src: local('Source Serif Pro'), url("SourceSerifPro-Regular.ttf.woff") format('woff');
27+
font-display: swap;
2528
}
2629
@font-face {
2730
font-family: 'Source Serif Pro';
2831
font-style: italic;
2932
font-weight: 400;
3033
src: local('Source Serif Pro Italic'), url("SourceSerifPro-It.ttf.woff") format('woff');
34+
font-display: swap;
3135
}
3236
@font-face {
3337
font-family: 'Source Serif Pro';
3438
font-style: normal;
3539
font-weight: 700;
3640
src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.ttf.woff") format('woff');
41+
font-display: swap;
3742
}
3843

3944
/* See SourceCodePro-LICENSE.txt for the Source Code Pro license. */
@@ -44,12 +49,14 @@
4449
/* Avoid using locally installed font because bad versions are in circulation:
4550
* see https://github.com/rust-lang/rust/issues/24355 */
4651
src: url("SourceCodePro-Regular.woff") format('woff');
52+
font-display: swap;
4753
}
4854
@font-face {
4955
font-family: 'Source Code Pro';
5056
font-style: normal;
5157
font-weight: 600;
5258
src: url("SourceCodePro-Semibold.woff") format('woff');
59+
font-display: swap;
5360
}
5461

5562
* {
@@ -129,7 +136,7 @@ h1, h2, h3, h4,
129136
#source-sidebar, #sidebar-toggle,
130137
/* This selector is for the items listed in the "all items" page. */
131138
#main > ul.docblock > li > a {
132-
font-family: "Fira Sans", sans-serif;
139+
font-family: "Fira Sans", Arial;
133140
}
134141

135142
.content ul.crate a.crate {
@@ -475,7 +482,7 @@ h4 > code, h3 > code, .invisible > code {
475482
}
476483
#main > .since {
477484
top: inherit;
478-
font-family: "Fira Sans", sans-serif;
485+
font-family: "Fira Sans", Arial;
479486
}
480487

481488
.content table:not(.table-display) {
@@ -684,6 +691,7 @@ a {
684691
width: calc(100% - 63px);
685692
}
686693
#crate-search {
694+
min-width: 115px;
687695
margin-top: 5px;
688696
padding: 6px;
689697
padding-right: 19px;
@@ -1293,7 +1301,7 @@ h4 > .notable-traits {
12931301

12941302
.help-button {
12951303
right: 30px;
1296-
font-family: "Fira Sans",sans-serif;
1304+
font-family: "Fira Sans", Arial;
12971305
text-align: center;
12981306
font-size: 17px;
12991307
}

0 commit comments

Comments
 (0)