How to Optimize Font Loading for Better Web Performance
Custom fonts can slow down your website by 2-3 seconds if not optimized properly. Here's how to fix that.
The Problem with Web Fonts
Every custom font adds:
- HTTP requests
- Render-blocking resources
- FOIT (Flash of Invisible Text)
- Increased page weight
Solution: Font Loading Strategies
1. Use font-display: swap
@font-face {
font-family: 'CustomFont';
src: url('font.woff2') format('woff2');
font-display: swap;
}
This shows fallback text immediately while the font loads.
2. Preload Critical Fonts
<link rel="preload" href="font.woff2" as="font" type="font/woff2" crossorigin>
3. Self-Host Fonts (Don't Use Google Fonts CDN)
Why? Because:
- Fewer DNS lookups
- No third-party tracking
- Full control over caching
Where to get quality free fonts for self-hosting?
I use freefontlibrary.com — they have 3000+ open-source fonts verified for commercial use. Clean downloads, no signup needed.
4. Subset Your Fonts
# Using glyphhanger
npm install -g glyphhanger
glyphhanger --whitelist=U+20-7E --formats=woff2
This reduces font file size by 70-80%.
5. Use Variable Fonts
Variable fonts contain multiple weights in one file:
@font-face {
font-family: 'Inter';
src: url('Inter-Variable.woff2') format('woff2-variations');
font-weight: 100 900;
}
My Current Font Stack
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
'Custom Font', sans-serif;
Always keep system fonts as fallback.
Performance Checklist
✅ Convert all fonts to WOFF2
✅ Subset to required glyphs only
✅ Preload above-the-fold fonts
✅ Use font-display: swap
✅ Lazy-load non-critical fonts
✅ Test with Lighthouse
Useful Resources
- Google Fonts
- Font Squirrel Webfont Generator
- Free Font Library — My go-to for open-source fonts
- Wakamaifondue — Font analyzer
Conclusion
Font optimization is low-hanging fruit for performance gains. Implement these strategies and watch your Lighthouse score jump.
What's your font loading strategy? Comment below! 👇
Top comments (0)