A CJK web font ships 65,000+ glyphs and weighs 10-20MB. Your page uses 200 of them. pyftsubset (from the fonttools package) is the fix - and it works for Latin fonts too.
Install and basic use
pip install fonttools brotli
pyftsubset myfont.ttf \
--text='Your actual content here' \
--output-file=myfont-subset.woff2 \
--flavor=woff2
That is the whole pipeline. The --text flag keeps exactly those glyphs; --flavor=woff2 compresses with Brotli (needs the brotli package).
Subsetting by Unicode ranges
For languages you cannot enumerate (user-generated content), subset by range instead:
pyftsubset myfont.ttf \
--unicodes='U+0000-00FF,U+2000-206F' \
--output-file=latin-subset.woff2 --flavor=woff2
U+0000-00FF covers Latin + Western European; U+2000-206F adds the typographic punctuation block (curly quotes, en/em dashes).
The numbers
- Full Latin TTF: ~300KB → woff2 subset: ~15-30KB
- Keeping ligatures and kerning: add
--layout-features='kern,liga'(default keeps them; strip with--layout-features=''for maximum savings) - Variable fonts:
--instance='wght=400'pins one weight before subsetting
The verification step
After subsetting, verify what actually renders in your test page - subsetting bugs (missing glyphs falling back to system fonts) show up as a DIFFERENT typeface on screen. Screenshot and identify on-device with Typeye; if the identifier names your system font instead of your subset, a glyph fell out of the subset range.
CI integration
Run pyftsubset in your build pipeline, compare output size, and fail the build if a font grows unexpectedly. Fonts are the asset class nobody watches - this is the one-line guard.
Ship the subset. Keep the full font as a build artifact, not a payload.
Top comments (0)