Skip to content

Self-host fonts and inline global CSS to cut render-blocking#27

Merged
pedropaulovc merged 1 commit into
mainfrom
perf/self-host-fonts-inline-css
May 29, 2026
Merged

Self-host fonts and inline global CSS to cut render-blocking#27
pedropaulovc merged 1 commit into
mainfrom
perf/self-host-fonts-inline-css

Conversation

@pedropaulovc

Copy link
Copy Markdown
Contributor

Lighthouse flagged two render-blocking requests on the critical path (~1,630ms est. savings):

Request Why blocking
fonts.googleapis.com/css2?family=… cross-origin stylesheet, ~750ms before font bytes even start
/_astro/Layout.*.css first-party ~6KB stylesheet, ~160ms

Fix

  • Self-host Inter + Playfair Display via Astro's Fonts API. Fonts are downloaded, subset to latin, and served from /_astro/fonts/*.woff2 (static assets, bypass the Worker). The <Font> component inlines @font-face and preloads the font bytes instead of waiting on a cross-origin CSS round-trip. Generated metric-matched fallbacks also cut CLS during swap.
  • Inline the global stylesheet (build.inlineStylesheets: "always") — no more render-blocking <link>. Pages are SSR'd per request, so there's no shared-cache benefit lost.
  • Theme vars --font-sans / --font-serif now resolve to the self-hosted families; no component changes needed (all use the font-sans/font-serif utilities).

Verified in rendered HTML

  • googleapis/gstatic references: 0
  • External <link rel="stylesheet">: 0
  • 3 same-origin font preloads + @font-face all → /_astro/fonts/*.woff2
  • Build green, lint clean
Caveat

Self-hosted fonts require network at build time (CI fetches from Google once). The Cloudflare build has this; flagging only in case of a future air-gapped build env.

🤖 Generated with Claude Code

Lighthouse flagged two render-blocking requests on the critical path: the
cross-origin Google Fonts stylesheet (~750ms) and the first-party global
stylesheet (~6KB, ~160ms).

Self-host Inter and Playfair Display via Astro's Fonts API. They are now
downloaded, subset to latin, and served from /_astro/fonts (bypassing the
Worker). The <Font> component inlines @font-face CSS and preloads the font
bytes instead of waiting on a cross-origin stylesheet, and generates
metric-matched fallbacks that also reduce CLS.

Inline the small global stylesheet (build.inlineStylesheets: "always") so it
no longer emits a render-blocking <link>; pages are SSR'd per request, so
there is no shared-cache benefit lost.

Verified in rendered HTML: zero googleapis/gstatic references, zero external
stylesheet links, font @font-face/preloads all point to same-origin
/_astro/fonts/*.woff2.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 29, 2026 15:33
@pedropaulovc
pedropaulovc enabled auto-merge May 29, 2026 15:33

@pedropaulovc pedropaulovc left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
decipher-ms 17747f1 Commit Preview URL

Branch Preview URL
May 29 2026, 03:34 PM

@pedropaulovc
pedropaulovc merged commit 71e3b0f into main May 29, 2026
2 of 3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pedropaulovc
pedropaulovc deleted the perf/self-host-fonts-inline-css branch May 29, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants