CommunityCoding & Developmentgithub.com

web-font-loading

Make web fonts fast and stable. Audits HTML and CSS for @font-face rules without font-display or with block, fonts without a WOFF2 source, Google Fonts links without display=swap or preconnect, too many weights, font preloads missing crossorigin (double downloads) or pointing at unused files, CSS @import of font stylesheets, icon fonts, too many font files and swapping fonts without metric-matched fallbacks. Covers self-hosting Google Fonts, subsetting with unicode-range and pyftsubset, variable fonts and size-adjust fallback faces that remove font-swap layout shift. Use when Lighthouse flags "Ensure text remains visible during webfont load" or "Font display", text is invisible or flashes while loading, fonts cause layout shift, or the user wants to self-host Google Fonts.

What is web-font-loading?

web-font-loading is a Claude Code agent skill that make web fonts fast and stable. Audits HTML and CSS for @font-face rules without font-display or with block, fonts without a WOFF2 source, Google Fonts links without display=swap or preconnect, too many weights, font preloads missing crossorigin (double downloads) or pointing at unused files, CSS @import of font stylesheets, icon fonts, too many font files and swapping fonts without metric-matched fallbacks. Covers self-hosting Google Fonts, subsetting with unicode-range and pyftsubset, variable fonts and size-adjust fallback faces that remove font-swap layout shift. Use when Lighthouse flags "Ensure text remains visible during webfont load" or "Font display", text is invisible or flashes while loading, fonts cause layout shift, or the user wants to self-host Google Fonts.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/saizul/web-performance-skills/tree/HEAD/skills/web-font-loading

Installed? Explore more Coding & Development skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Web font loading

Goal: text is readable immediately, the web font arrives early (one or two preloaded WOFF2 files at most), and the swap from fallback to web font does not move the layout.

Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).

When to use

  • Lighthouse "Ensure text remains visible during webfont load", "Font display" insight
  • FOIT (invisible text) or FOUT with a visible jump
  • Self-hosting Google Fonts or Adobe Fonts alternatives, choosing weights, subsetting
  • Text LCP with a large render delay

When not to use

  • Fonts are fine and other CSS blocks rendering: render-blocking-resources
  • Font files not cached: caching-headers-review

Workflow

  1. Collect the HTML and the CSS that declares the fonts (theme stylesheet, Google Fonts CSS):
    curl -sL https://example.com/ -o page.html
    curl -sL https://example.com/css/site.css -o site.css
    
  2. Run the audit (read-only):
    python3 scripts/font_audit.py page.html site.css
    python3 scripts/font_audit.py page.html site.css --max-files 4 --json
    
  3. Choose font-display per font:
    • body text: swap (always visible) or optional (no swap after ~100 ms; best for CLS, the web font shows on the next page view from cache)
    • brand headings: swap with a metric-matched fallback
    • icon fonts: block is acceptable, but prefer inline SVG icons
  4. Reduce files: keep 2-3 weights, or one variable font; WOFF2 only; subset to the scripts the site uses (unicode-range splits download only what a page needs). Commands in references/font-loading.md.
  5. Self-host Google Fonts when possible: removes two origins (fonts.googleapis.com, fonts.gstatic.com) from the critical path. Download the WOFF2 files for the needed subsets and weights, write the @font-face rules (template in the reference), check the font license (Google Fonts are OFL/Apache and allow self-hosting).
  6. Preload only the 1-2 fonts used above the fold, with type="font/woff2" and crossorigin, using exactly the URL in @font-face.
  7. Add metric overrides to a fallback face (size-adjust, ascent-override, descent-override) so the swap does not shift text; values for common pairs and how to compute them are in references/font-loading.md.
  8. Show the CSS/HTML diff, ask, apply, verify: re-run the script; in DevTools Network each font file should download once, early, with a 200 and long caching.

Output

Fonts: 4 @font-face rules, Google Fonts (Inter 6 weights), 1 preload
1. Preload brand.ttf has no crossorigin -> downloads twice                     [high]
2. "Brand Sans": no font-display, TTF/WOFF only -> WOFF2 + swap                [medium]
3. Google Fonts without display=swap, 6 weights -> self-host Inter variable    [medium]
4. Fallback "Brand Sans Fallback" with size-adjust: 104% to avoid swap shift   [info]
Result: 2 font files (was 8), ~70 KB (was ~310 KB). CSS diff below, not applied yet.

Individual skills in this repo

This repo contains 2 individual skills — each has its own dedicated page.

image-optimization-audit

Audit page images for weight, format, sizing and loading behaviour, then produce a conversion and markup plan. Reads saved HTML (missing width/height, srcset without sizes, large images without srcset, lazy-loading on the first images or missing further down, JPEG/PNG outside a picture element with AVIF/WebP, animated GIFs) and HAR files (images over a KB budget, legacy formats with real byte counts, uncompressed SVG, broken image requests, total image weight). Includes exact commands for cwebp, avifenc, ImageMagick and sharp, and responsive image markup. Use when images are the heaviest part of a page, Lighthouse flags "Properly size images", "Serve images in next-gen formats", "Efficiently encode images", "Defer offscreen images" or "Improve image delivery", or the user asks to convert images to WebP/AVIF or set up srcset.

render-blocking-resources

Find and remove what blocks first paint. Lists the critical path of a saved HTML page in document order and flags parser-blocking scripts in the head and early body, third-party stylesheets and scripts on the critical path, CSS @import chains, document.write, A/B-testing anti-flicker snippets, oversized inline CSS, too many blocking stylesheets, missing and excessive preconnect hints. Explains defer vs async vs type=module, critical CSS inlining, non-blocking CSS loading and resource hints with copy-paste snippets. Use when Lighthouse reports "Eliminate render-blocking resources", "Render blocking requests" or a long critical request chain, FCP or LCP render delay is high, the page stays white for seconds, or the user asks whether to use defer or async.

Related Skills