Skip to content

Self-host fonts, preload chart data and cache static assets - #55

Merged
alies-dev merged 4 commits into
masterfrom
alies-dev/frontend-perf
Nov 21, 2026
Merged

alies-dev merged 4 commits into
masterfrom
alies-dev/frontend-perf

Conversation

@alies-dev

Copy link
Copy Markdown
Contributor

Context

A cold first paint on shepherd.dev takes about 2.3 s on every page. About 1.5 s of that is DNS, TCP and TLS to the origin, which the frontend cannot change. The part it controls is the render-blocking Google Fonts stylesheet. It lives on a third-party origin that needs its own connection, and it adds about 260 ms to FCP on desktop and 430 ms on mobile (measured on production by blocking it), plus 4 requests and 60 KB.

The font swap also re-wraps the home page lead paragraph, which gives a 0.028 CLS on mobile. Static assets have no Cache-Control. The chart data request only starts after history.js runs. Hovering the selected range preset turns its label white on near-white.

Solution

  • Self-host IBM Plex as latin WOFF2 subsets: the 4 faces in use, 32 KB instead of 60 KB, with the OFL licence and the script that builds them. font-display: swap, an Arial fallback scaled to the Plex metrics so the swap does not move text, and a preload of the first-screen fonts only.
  • Preload history.json with a Link header, so the chart data request starts together with the document.
  • Under Apache (the Docker image), versioned assets and fonts get max-age=31536000, immutable, and mod_deflate compresses HTML, CSS, JS, SVG and JSON. The image enables mod_headers.
  • The hover rule no longer applies to the pressed preset, so its label stays readable.

Local A/B on PHP 8.3 with brotli, a 200 ms origin delay and the same data:

Before After
Home FCP, desktop 1.78 s 0.46 s
Home FCP, mobile 1.86 s 0.51 s
History FCP, desktop 1.77 s 0.48 s
Home CLS, mobile 0.028 0
Home bytes 75.6 KB 47.9 KB

The local "before" includes slow DNS to Google from the test machine. The production figure above (260 ms and 430 ms from blocking the Google stylesheet) is the cleaner number.

HTML is not compressed in PHP: nginx in production already serves brotli to browsers, and PHP gzip would replace it with a larger body. Cache headers for /assets/ and Vary: Accept-Encoding on the production nginx have to be set in Plesk.

- Drop the render-blocking fonts.googleapis.com stylesheet and its two preconnects (a new origin, DNS, TCP and TLS before the first paint).
- Ship latin WOFF2 subsets of the four faces in use (Sans 400/500, Mono 400/500, 32 KB instead of 60 KB), with the OFL licence next to them.
- Size-adjusted Arial fallback for Plex Sans so the swap does not reflow the page (home mobile CLS 0.028 to 0).
- Preload the fonts the first screen needs: Sans 400 everywhere, Mono 500 on the home page.
- Versioned assets (?v=<mtime>) and fonts get max-age=31536000, immutable; unversioned files a day.
- Compress HTML, CSS, JS and SVG with mod_deflate (it skips already encoded responses).
- Enable mod_headers in the Docker image.
- The chart data request starts with the document instead of after history.js has run, one round trip earlier.
- fetchpriority=low keeps it behind the stylesheet and scripts.
- The hover rule (0,3,1) beat the pressed rule, so the pressed button under the pointer got the wash background with the solid foreground, white on near-white.
@alies-dev alies-dev self-assigned this Nov 21, 2026
@alies-dev
alies-dev merged commit 4cf71c4 into master Nov 21, 2026
4 of 6 checks passed
@alies-dev
alies-dev deleted the alies-dev/frontend-perf branch November 21, 2026 15:28
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.

1 participant