Coockar

Published: 1 min read

Subsetting a web font down to 23KB

Extracting only the Latin glyphs from a variable font for self-hosting — the pyftsubset invocation and three pitfalls worth checking.

I wanted exactly one Latin display face. The distributed woff2 weighs 59KB, and since the site pairs it with system CJK fallbacks, most of its glyphs would never render. Running fonttools’ pyftsubset to keep only the Latin ranges brought it down to 23KB.

The command

pyftsubset Font-Variable.woff2 \
  --output-file=font-latin.woff2 \
  --flavor=woff2 \
  --unicodes="U+0000-00FF,U+2000-206F,U+2190-21FF" \
  --layout-features='*'

The ranges cover Basic Latin, Latin-1 Supplement, general punctuation, and arrows. Don’t omit --layout-features='*' — without it, OpenType features like ligatures and kerning are stripped.

Three pitfalls I checked

  • The variable weight axis survived (inspect the fvar table)
  • font-display: swap is set, accepting FOUT so text still renders if the font fails
  • The license permits distributing a subset. The OFL requires the full license text to accompany any bundled, modified version

Takeaway

Subsetting is a do-once job, and the 59KB→23KB saving applies to every page. The one thing not to skip is attribution: the full license text lives in the repository-root NOTICE file.