In Lighthouse’s mobile run, one file cost my home page 600 ms of Largest Contentful Paint: a 131 KB variable font. The fix was to ship less of the font. The harder part came after, with the font that shows before it arrives.
The numbers in the first half come from the design this site had in September, which set its headings in Bricolage Grotesque. The numbers at the end come from today’s design, measured on 27 October.
Three axes for one weight
The headings came from Fontsource’s variable package for Bricolage, and from its “standard” file: three axes in one file, weight from 200 to 800, width from 75% to 100%, and optical size. For latin characters alone it was 131 KB. Nearly every heading on the site used a single point on one of those axes: weight 800.
Lighthouse’s simulated mobile network charges every web-font byte before first paint, so the home page paid for all three axes to draw a headline in one weight.
Fontsource also ships each weight as its own static file. The latin file for 800 is 22 KB. The change was one import:
/* Display face ships one static weight (22 KB) instead of the 131 KB variable
file: every display use on the site is 800. */
@import "@fontsource/bricolage-grotesque/800.css";It replaced @import "@fontsource-variable/bricolage-grotesque/standard.css", and the home page’s preload moved to the one file. The median mobile scores of the three pages I measured went back to 100, 100 and 99, with CLS 0 on all three.
Most of the cost was the axes I didn’t use. Fontsource’s weight-only variable file for the same latin characters is 41 KB, less than two static weights, so from a second weight on it would have been the smaller choice. For one weight, the static file is the smallest of the three.
A fallback that takes the font’s space
A web font arrives after the page’s first paint, and on a slow phone connection well after it. Fontsource’s faces use font-display: swap: the browser paints the text in the next font in the stack and swaps when the file lands. If the two fonts take different amounts of space, lines rewrap at the swap and text moves. That movement is what Cumulative Layout Shift counts.
The fix is a fallback face cut to the web font’s size: an @font-face over a font the reader already has, with overrides that make it take the web font’s space. capsize’s createFontStack works them out from the two fonts’ metrics. This site’s body text is Lora, and its fallback is Georgia:
@font-face {
font-family: "Lora Fallback";
src: local("Georgia");
ascent-override: 95.8281%;
descent-override: 26.1003%;
line-gap-override: 0%;
size-adjust: 104.9796%;
}--font-body: Lora, "Lora Fallback", Georgia, serif;size-adjust scales Georgia until a line of ordinary text is as wide in it as in Lora. The three overrides give it Lora’s ascent, descent and line gap, so its text sits where Lora’s will. Measured in Chrome, the same line set in the fallback comes out 0.28% narrower than in Lora, and at the normal line height exactly as tall. The swap changes the letters and, nearly always, nothing else.
Bold isn’t regular
capsize’s numbers describe a font’s regular weight, and my headings weren’t regular. Under a fallback sized for regular Arial, titles took 4% less width than they would in Bricolage 800, so they wrapped to fewer lines until the font arrived, and pushed the page down when it did: CLS 0.03 on a phone 412 pixels wide.
The fix was to cut the fallback for the weight the headings used: Arial Bold, with a size-adjust measured in Chrome against Bricolage 800 on the site’s own titles (103.3%), and the vertical overrides worked out again from Bricolage’s metrics. After that, every title wrapped the same before and after the swap.
A few days later, in the redesign, I did it again. Today’s design sets bold text in Lora 600 and its buttons in Cormorant Garamond 600, and I gave neither weight a fallback of its own. The browser filled the gap by bolding the regular fallback itself, at the regular weight’s size. Measured in Chrome over 12,000 characters of this site’s posts, that made-up bold came out 2% narrower than Lora 600. Now each 600 weight has its own face over the real bold cut, measured the same way:
@font-face {
font-family: "Lora Fallback";
font-weight: 600;
src: local("Georgia Bold"), local("Georgia-Bold");
ascent-override: 108.8498%;
descent-override: 29.647%;
line-gap-override: 0%;
size-adjust: 92.4209%;
}The font-weight: 600 is what makes it the bold face of “Lora Fallback”. Over the 12,000 characters it was sized on, it is now as wide as Lora 600. On my DNS post, the shift at the swap went from 0.00226 to 0.
Italic isn’t upright
The redesign sets its excerpts in Lora italic. Their fallback was Georgia Italic, but sized with the upright cut’s numbers, so the excerpts rewrapped when Lora arrived: CLS 0.0027 on a phone. capsize’s metrics for the italic cut took it to 0.
Subsets download together
One more job for the fallback. Fontsource’s per-subset CSS files carry no unicode-range, so importing latin and latin-ext for one face makes the browser download both. On this site that was ten font files where five were needed. I ship latin only now, and a character outside latin falls back, glyph by glyph, to the metric-matched face.
Where it stands
Today’s design has three families and six static files: Cormorant Garamond 400 and 600, Lora 400, its italic and 600, and JetBrains Mono 400, each 21 to 23 KB. Together they weigh about what the one variable file did. The difference is that a page downloads only the faces it sets: three on Writing (67 KB), five on the home page (111 KB), all six on a post with bold text (133 KB). Every page preloads the display face. On the home page that face sets the headline and the faint 07 behind it, which is the element Lighthouse counts as the largest paint.
Lighthouse’s mobile run, median of three, on the live site: 99 for the home page, 100 for Writing, 99 for a post, and CLS 0 on all three.
What a fallback can’t match
That CLS 0 comes with a catch. Lighthouse’s default run loads the page at full speed and works out the slow timings afterwards, and on today’s pages the fonts arrive almost at once, so nothing visibly swaps. To see a swap, the network has to be slow for real. Lighthouse does that too, at the same phone size:
bunx lighthouse https://siegb.dev/blog/672px-wide-on-a-430px-phone/ --throttling-method=devtoolsOn my post about a blog 672 pixels wide, that run finds a shift of 0.05 in two runs out of three, all of it in the opening paragraph. On that paragraph’s first line, Georgia fits one more word than Lora, and every break after it falls somewhere else. When Lora arrives the paragraph keeps its eleven lines, so nothing below it moves, but its words reflow, and the run of text after its inline code starts a line lower. Moving text is what CLS counts. In the third run the paragraph didn’t paint until Lora was in, so there was nothing to move.
Metric matching evens out the width of a line of ordinary text, not of every word in it. Further down the same post, two paragraphs trade a line at the swap as well, out of view, where moving doesn’t count.
0.05 is under the 0.1 that Google calls good, and it’s the only shift left on the pages I measured. The way to 0 is font-display: optional, which gives the font a moment and otherwise keeps the fallback for that visit: on a slow first visit, the page stays in Georgia.
The rule
Count the weights, styles and axes you set, and ship the smallest file that covers them; for one weight, that’s a static file. Give every weight and style that shows before the font arrives its own fallback face, measured against that weight, over the fallback font’s matching cut. Then measure the swap on a slow network, at a phone’s width, on a long page, because Lighthouse’s default run can miss it. And expect some text to still move: a fallback can match a font’s size, not its letters.