How to Optimize Web Fonts for Performance
· Category: Web Performance
Short answer
Web fonts can block rendering and cause layout shifts. Optimizing them involves choosing efficient formats, limiting subsets, and controlling loading behavior.
Steps
- Use modern formats like WOFF2 for the best compression.
- Subset fonts to include only the characters your site needs.
- Add
font-display: swapto show fallback text immediately. - Preload critical fonts with
<link rel="preload" as="font">. - Self-host fonts instead of relying on external services when possible.
Tips
- Use the
size-adjustdescriptor to reduce layout shift when fonts swap. - Limit the number of font families and weights to reduce requests.
- Variable fonts combine multiple weights into a single file.
Common issues
- Flash of Invisible Text (FOIT) occurs when
font-displayis omitted. - Third-party font services add DNS and connection overhead.