ARTICLE - Dev Stack & Tools

CJK Web Font Subsetting

The goal is not a magic file size but avoiding glyphs a page never uses. Static subsets suit stable copy; unicode-range shards suit changing content. Both need real-corpus checks for missing glyphs and fallback behavior.

2026-11-25 16IDC Original 14 views
Advertisement

CJK web fonts may contain many glyphs a page never uses, and WOFF2 compression alone does not remove them. For stable copy, build a static subset from the full page corpus. For frequently changing content, split the font into resources and declare their coverage with unicode-range, so the browser can request resources matched by the page's characters. Choose only after checking font licensing, build ownership, content churn and fallback behavior.

Separate compression, subsetting and on-demand loading

These approaches affect different parts of font delivery. See MDN's unicode-range reference for browser matching behavior:

  • WOFF2 changes font encoding and packaging; it does not automatically remove glyphs absent from page copy.
  • Static subsetting creates a file containing glyphs from a specified character set. New characters outside the corpus need a fallback font or a rebuilt subset.
  • Unicode-range sharding splits a font into multiple files and declares each file's code-point coverage in CSS. The browser selects matching resources for characters in use. A unicode-range declaration alone does not shrink one large font file.

Choose based on whether the content is stable or dynamic. Static subsets are straightforward for small, stable pages such as a login or campaign page. News, comments and user names change continuously; they need a maintained mapping with broad coverage or an acceptable system-font fallback. A third-party font service also introduces external requests and coverage limits.

CJK font request path Split files first, then map characters with unicode-range Page text Range match Fetch shard Render or fallback A matched file downloads whole; unmatched files are skipped Scope: browsers match font resources to characters on the page
Figure 1: CJK font request path (Scope: browsers match font resources to characters on the page)
Approach Suitable when What you maintain Common failure
Full self-hosted font The page needs broad coverage and can accept the full file transfer Font version, license and cache Fetching glyphs the page never uses
Static subset Page copy can be collected and changes infrequently Full corpus, rebuilds and fallback New or dynamic text has missing glyphs
unicode-range shards Content changes often and should load from separate resources Shard CSS, file paths and cache version Incomplete mapping or missing file
Third-party font CSS You cannot build or host font assets Upstream availability, privacy and CORS Missing coverage or blocked external request

Build a static subset with pyftsubset

First confirm that the font license permits web embedding, self-hosting and the required redistribution. Then collect text from every page that may render the font: not just the first-screen body copy, but navigation, buttons, error messages, dynamic labels, user-visible names and full-width punctuation. Maintain the corpus through the site content or build process rather than using a single homepage headline as a proxy.

With fontTools installed with WOFF2 support, pass a UTF-8 text file to pyftsubset. The example assumes Python 3.11 or later; replace the input font and corpus paths:

python3 -m venv .venv
. .venv/bin/activate
python -m pip install fonttools brotli
pyftsubset ./source-font.ttf \
  --text-file=./page-copy.txt \
  --flavor=woff2 \
  --layout-features='*' \
  --output-file=./dist/site-subset.woff2
test -s ./dist/site-subset.woff2 && wc -c ./dist/site-subset.woff2

What to verify: the command creates a non-empty WOFF2 file and wc -c reports its actual byte count; that is an observed build result, not a universal size target. After connecting the file to the page, test the collected corpus and dynamic content route by route for tofu, unexpected system-font fallback and missing punctuation. New copy must enter the corpus and trigger a rebuild. Output size or glyph count alone does not prove coverage.

If text comes from multiple routes, include a build-time corpus assembled from them. When user-generated content cannot be enumerated, provide a deliberate fallback for less common characters or use a more complete sharding strategy. Keep the font's license and source with the build artifacts.

Generate shard mappings with cn-font-split

The upstream cn-font-split project can split supported fonts into resources and generate result.css. Its current README (checked 2026-11-28) requires Node.js 22 or later and pnpm 12 for the documented installation; check the current requirements and breaking changes before integrating it.

pnpm install --global cn-font-split
mkdir -p ./dist/fonts
cn-font-split -i ./source-font.ttf -o ./dist/fonts

What to verify: the output directory should contain font shards and result.css; each @font-face entry's src, unicode-range and family name must match a generated file. After deployment, filter the browser Network panel by Font to confirm that the page requests matching shards rather than a full font. Add a test character covered by a shard and verify the corresponding request.

Publish the generated mapping and files as one versioned artifact. When replacing a font or regenerating shards, update the CSS and font files together so cached HTML or stylesheets do not point to removed files. Test all routes and target browsers; a successful build alone is not acceptance.

Check coverage and troubleshoot before release

Release checks should answer three questions: are the glyphs present, can the browser fetch the resources, and does it load only the expected resources?

  1. Check character coverage: browse real page copy, punctuation, names and dynamic states. If a glyph is missing, verify that the source font supports it, then inspect the subset corpus or shard unicode-range.
  2. Check requests: filter the browser Network panel by Font and review URLs, status codes, transfer bytes and duplicate requests. A 404 usually points to a mismatch between CSS paths and deployed files; for cross-origin fonts, inspect CORS response headers.
  3. Check rendering: confirm the font-family order, actual weight and fallback. font-display: swap changes what is displayed while a font loads; it does not reduce bytes. If glyphs shift, also check fallback-font metrics and whether the intended font arrives in time.
  4. Check cached releases: use cache settings appropriate to the deployment for content-hashed font files, and update CSS references when fonts change. Old CSS pointing to deleted files can leave some pages without glyphs.

unicode-range is neither a licensing boundary nor a guarantee that a browser can fetch a resource. For third-party CSS, also assess external-domain access, privacy terms, CORS responses and provider coverage.

Limitations

  • A static subset only covers characters included in the build corpus and supported by the source font; dynamic content or additional languages may fall outside it.
  • Shard granularity, CSS output and filenames depend on the tool and version. Before upgrading, check CLI options, Node or Python requirements and generated output.
  • unicode-range declares code-point ranges, not language completeness or visual coverage. Characters for one language may occupy different Unicode blocks and font coverage.
  • Check font terms separately for embedding, conversion, caching, mirroring and redistribution. “Free to use” does not automatically permit reselling shards inside themes or templates.
  • Third-party font requests depend on domain access, browser CORS and upstream resources. If availability, privacy or compliance matters, assess self-hosting or system-font fallback.

FAQ

Which reduces a CJK download: unicode-range or font subsetting?

Neither alone. unicode-range selects whether a resource is requested; subsetting removes unused glyphs from a font file. If the page maps to 1 WOFF2 file, that whole file is still downloaded. Split the font into separate resources and map ranges if the browser should fetch only matching shards; verify the requests in the Network panel.

Why does a static WOFF2 subset show missing glyphs?

First confirm that the source font contains the glyph. Then check whether the subset corpus included it; for shards, verify that the code point falls within a CSS unicode-range and that the mapped file exists. Inspect the font request in Network and confirm that the fallback font contains the glyph. Add the missing coverage, rebuild and deploy the CSS and WOFF2 files together.

When is a static subset not a fit for dynamic names and comments?

Not as the only coverage strategy for dynamic text. Divide the test corpus into at least 2 groups—fixed interface copy and dynamic names or comments—and check the subset and fallback for both. If consistent glyph shapes matter, maintain a complete shard map and test uncommon names, symbols and scripts. Compare caching, request count, license terms and build maintenance before choosing.

How do I avoid stale CSS requesting deleted font shards?

Publish the new CSS and font files together. Keep the old files until cached CSS no longer references them; use content-hashed filenames to distinguish versions. For rollback, restore the matching CSS and font set, then confirm in Network that font requests no longer return 404.

References

Related Providers

  • Fontsource: assess its font packages when open-source fonts should ship with the frontend build and CSS subsets or Unicode ranges should manage loading.
  • Google Fonts: check its CSS API, font coverage and data-handling terms when self-hosting is not available and third-party requests are acceptable.
  • Chinese Webfont Project: review its font families, licensing and hosted assets when a Chinese sharding service fits the project.

Community & Resources

Original source: 16IDC Original ↗