Skip to content

Commit ebb98f1

Browse files
committed
perf: Load fonts with font-display swap, preloads and caching
Mobile Lighthouse attributes ~400 ms of first-paint delay to the fonts blocking text rendering: - font-display: swap on all six faces, so text renders in the fallback font until the webfonts arrive. - Preload the two above-the-fold fonts (body Noto Sans 400 and heading IBM Plex Mono 600), so they usually arrive before first paint anyway. - Cache the UI bundle assets for a day via netlify.toml headers (the Lighthouse cache-lifetimes finding; a day keeps a stale-css window after deploys short since the file names are not content-hashed).
1 parent 3aa7294 commit ebb98f1

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

netlify.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@
1111
from = "/home/stable/release_notes.html"
1212
to = "/home/stable/release-notes"
1313
status = 301
14+
15+
# The UI bundle assets change only when a new site version is deployed;
16+
# a day of caching covers the Lighthouse "efficient cache lifetimes" finding
17+
# without risking a long-lived stale css after a redesign deploy.
18+
[[headers]]
19+
for = "/_/*"
20+
[headers.values]
21+
Cache-Control = "public, max-age=86400"

ui/src/css/fonts.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* How do fonts work in this build setup?
22
* Fonts are installed from fontsource packages.
3-
* In the file ./gulp.d/tasks/build.js there is an action that copies the font files
4-
* from the installed packages into the output directory, based on matching file names.
5-
* search for 'fontsource' in the file, and you will find a post CSS action.
3+
* The build (ui/build.mjs) resolves the ~@fontsource urls below and emits the
4+
* font files into the bundle's font/ directory.
65
*/
76

87
/* Noto Sans - the base font for the body */
98

109
@font-face {
10+
font-display: swap;
1111
font-family: "Noto Sans";
1212
font-style: normal;
1313
font-weight: 400;
@@ -17,6 +17,7 @@
1717
}
1818

1919
@font-face {
20+
font-display: swap;
2021
font-family: "Noto Sans";
2122
font-style: normal;
2223
font-weight: 700;
@@ -28,6 +29,7 @@
2829
/* IMB Plex Mono - the header font */
2930

3031
@font-face {
32+
font-display: swap;
3133
font-family: "IBM Plex Mono";
3234
font-style: normal;
3335
font-weight: 400;
@@ -37,6 +39,7 @@
3739
}
3840

3941
@font-face {
42+
font-display: swap;
4043
font-family: "IBM Plex Mono";
4144
font-style: normal;
4245
font-weight: 600;
@@ -48,6 +51,7 @@
4851
/* Noto Sans Mono - The monospace font for code blocks */
4952

5053
@font-face {
54+
font-display: swap;
5155
font-family: "Noto Sans Mono";
5256
font-style: normal;
5357
font-weight: 400;
@@ -57,6 +61,7 @@
5761
}
5862

5963
@font-face {
64+
font-display: swap;
6065
font-family: "Noto Sans Mono";
6166
font-style: normal;
6267
font-weight: 500;

ui/src/partials/head-styles.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
<link rel="preload" href="{{{uiRootPath}}}/font/noto-sans-latin-400-normal.woff2" as="font" type="font/woff2" crossorigin>
2+
<link rel="preload" href="{{{uiRootPath}}}/font/ibm-plex-mono-latin-600-normal.woff2" as="font" type="font/woff2" crossorigin>
13
<link rel="stylesheet" href="{{{uiRootPath}}}/css/site.css">
24
<link rel="stylesheet" href="/_/pagefind/pagefind-modular-ui.css">

0 commit comments

Comments
 (0)