Repository navigation
Self-host fonts, preload chart data and cache static assets - #55
Merged
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 afterhistory.jsruns. Hovering the selected range preset turns its label white on near-white.Solution
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.history.jsonwith aLinkheader, so the chart data request starts together with the document.max-age=31536000, immutable, andmod_deflatecompresses HTML, CSS, JS, SVG and JSON. The image enablesmod_headers.Local A/B on PHP 8.3 with brotli, a 200 ms origin delay and the same data:
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/andVary: Accept-Encodingon the production nginx have to be set in Plesk.