Paj Digital Labs
All articles
Web Design & Engineering

Font Loading Without the Layout Shift: Subsetting, Preload and font-display

Webfonts are the last acceptable 200ms of jank. Self-hosting, subsetting to the glyphs you actually use, and the size-adjust trick that makes the fallback invisible.

Paj Digital Labs 2 min read
Web design workspace with desktop and laptop displays
Editorial illustration · Web Design & Engineering

A webfont is a render-blocking download of a file full of glyphs your page will never use, served from a domain that requires a DNS lookup and a TLS handshake before the first byte moves. And the industry's answer to this was font-display: swap, which trades invisible text for a visible layout shift when the font arrives.

You can do better. Fonts are the most optimizable asset on most pages because almost everything about them is waste.

Self-host. Always.

A third-party font CDN costs you a DNS lookup, a TCP connection, and a TLS handshake to a domain you do not control — before the font request even starts. On a cold connection that is 200–400ms of pure latency added to your LCP if the headline is set in a webfont. Which it is.

Self-hosting collapses all of that into a request to your own domain, which is already connected, already warm, and already HTTP/2. There is no argument for the CDN. Download the files, put them in /fonts, done.

Subset ruthlessly

A full Latin font file covers hundreds of glyphs. Your English-language site uses about 95 of them. Subsetting strips the rest:

bash
pip install fonttools brotli

pyftsubset Inter.var.woff2 \
  --unicodes=class="text-code-string">"U+0000-00FF,U+2010-2027,U+2030-205E" \
  --flavor=woff2 \
  --output-file=inter-latin.woff2

That range covers basic Latin, Latin-1 supplement, and the typographic punctuation you actually use — curly quotes, em dashes, ellipses. The result is typically 15–30 KB instead of 300 KB. On a content site, the font goes from the largest asset on the page to smaller than a single image.

Preload the critical font

html
<link rel=class="text-code-string">"preload" href=class="text-code-string">"/fonts/inter-latin.woff2" as=class="text-code-string">"font" type=class="text-code-string">"font/woff2" crossorigin>

Without preload, the browser discovers the font late: HTML, then CSS, then layout, then "oh, this element needs a font," then the request. Preload starts the download in parallel with the CSS. The crossorigin attribute is required even for same-origin fonts — font fetches are always CORS-mode, and a preload without it downloads the file twice. Yes, really. Check your network tab.

font-display and the size-adjust trick

css
@font-face {
    font-family: class="text-code-string">"Inter";
    src: url(class="text-code-string">"/fonts/inter-latin.woff2") format(class="text-code-string">"woff2");
    font-display: swap;
    size-adjust: 106%;
    ascent-override: 90%;
    descent-override: 22%;
}

body {
    font-family: class="text-code-string">"Inter", class="text-code-string">"Inter Fallback", system-ui, sans-serif;
}

font-display: swap shows fallback text immediately — good. The layout shift happens because the fallback font has different metrics: different x-height, different advance widths, different line height. The override descriptors let you reshape the fallback font's metrics to match the webfont. When the swap happens, the text barely moves.

Getting the values right takes ten minutes with a tool like Fontaine or the capsize calculator, and it is the difference between a CLS score of 0.15 and 0.01.

The checklist

1. Self-host WOFF2. Delete the CDN link. 2. Subset to the unicode ranges you use. 3. Preload the one font used above the fold. Only one — preloading everything preloads nothing. 4. font-display: swap with metric overrides on the fallback. 5. Variable fonts if you need multiple weights; one file beats four.

Fonts are 200 KB and 300ms of the average page, and every bit of it is recoverable. This is the cheapest performance work you will ever do.

Paj Digital Labs

The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.

Related reading