optimize-web-font-loading
Use when text is invisible during load or fonts cause a swap jump. Applies font-display, subsetting, preload and metric overrides.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- optimize-web-font-loading
- description
- Use when text is invisible during load or fonts cause a swap jump. Applies font-display, subsetting, preload and metric overrides.
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md351 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Optimize Web Font Loading
Web fonts are discovered late in CSS, block text paint, and change line breaks when they swap. Handled well they are invisible; handled badly they cause both a blank-text delay and a layout jump.
Procedure
-
Count what ships and subset it to the glyphs you use, cutting a 200 kB family to under 30 kB:
pyftsubset Inter.ttf --flavor=woff2 --unicodes-file=unicode.txt \ --layout-features='*' --output-file=inter-subset.woff2 -
Always set a display strategy;
swapshows fallback text immediately,optionalavoids the reflow entirely at the cost of not showing the font on slow loads:@font-face { font-family: Inter; src: url(/f/inter.woff2) format('woff2'); font-display: swap; } -
Preload the one font used above the fold so the request starts with the document:
<link rel="preload" href="/f/inter.woff2" as="font" type="font/woff2" crossorigin> -
Neutralise the swap shift with a metric-matched fallback via
size-adjust,ascent-overrideanddescent-overrideon a local@font-face. -
Use
unicode-rangeon subset faces so a page only downloads the Cyrillic block when it renders Cyrillic. -
Host same-origin; a third-party font origin adds DNS, TLS and connection latency you would otherwise avoid.
Pitfalls
- Loading four weights and styles when the design uses two; each is a separate blocking file.
font-display: blockwith a 3 s block period, which is the worst-case invisible-text delay.- Omitting
crossoriginon the preload, causing a second fetch because preload defaults to a different CORS mode. - Subsetting to Latin but leaving an emoji or symbol face unsubsetted at full size.
- Ignoring the fallback metrics, so the swap moves every line of copy by a few pixels and registers as CLS.
Verification
fc-scan --format '%{family} %{fontversion}\n' inter-subset.woff2 && ls -l inter-subset.woff2
The subset must be under 40 kB and the swap shift must not appear in a layout-shift observer. Report the file size and the CLS contribution from the font swap.
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.