font-pulse

Pulse · web performance

font-pulse

Audit how your built site loads web fonts: font-display, preloads, WOFF2, subsetting, unused weights and total font payload.

npm i -D @mrlouiswright/font-pulse

Published to GitHub Packages: add @mrlouiswright:registry=https://npm.pkg.github.com to .npmrc first (installing needs a token with read:packages).

What it checks

  • Loadingfont-display missing or block/auto; Google Fonts URLs without display=swap; third-party font hosts without preconnect.
  • Preloadsself-hosted fonts with no preload, preloads without crossorigin (double download), preloads of files no @font-face uses, and too many font preloads.
  • Formats and size@font-face without a WOFF2 source, font files over 100 kB (subset them), large fonts without unicode-range.
  • Wastefamilies declared but never used in font-family, weights and italic faces never used (headings and <strong> count as bold), more than six font files per page, and a per-page payload budget (default 300 kB).
  • Understands real CSSthe font shorthand, CSS custom properties, variable-font weight ranges, @import chains and inline styles.

Quick usage

CLI

npx font-pulse dist
npx font-pulse public --max-payload-kb 200 --fail-on medium
npx font-pulse _site --format markdown >> $GITHUB_STEP_SUMMARY

API

import { check, parseCss } from "font-pulse";
parseCss("@font-face{font-family:Inter;src:url(i.woff2) format('woff2')}").faces;
const report = check("dist", { maxPayload: 200 * 1024 });

Every option is documented in the font-pulse docs.

CI / GitHub Action

permissions:
  contents: read
  security-events: write   # only needed for the SARIF upload
jobs:
  font-pulse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
        with: { persist-credentials: false }
      - run: npm ci && npm run build   # produce the static site first
      - uses: MrLouisWright/font-pulse@v1
        with:
          path: dist
          fail-on: high
          sarif: font-pulse.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with: { sarif_file: font-pulse.sarif }