- Every page but Home, and the whole admin, loads on first visit: the main bundle drops from 579 kB to 314 kB (173 to 98 kB gzipped); a tab on an old build reloads once when a page chunk has gone - Home asks for events and the timeline alongside its own data, and the server preloads /api/front-page and the first hero photo - Hero headline rises in as one piece (it held back the page's largest paint), sized to stay within two lines; min-h in dvh; first slide fetched at high priority - Every raster upload gets a 640px copy (at upload, and at boot for older files); logos, avatars and card pictures load it and fall back to the full file - Login password checks run off the event loop; only admin requests are logged per request; ffmpeg runs at nice 19 on Linux - Page HTML is no-cache, so a deploy can't strand a cached page on missing assets; source maps are no longer linked - Migration 042: index person_awards by award - docs/performance.md, and gzip and HTTP/2 for nginx Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2.6 KiB
Performance
What keeps the site fast, and what nginx has to do for it.
nginx
In the site's server block (both are in nginx-dev):
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types text/css application/javascript text/javascript application/json
image/svg+xml application/xml application/rss+xml text/plain;
listen 443 ssl http2;
listen [::]:443 ssl http2;
Ubuntu's nginx.conf turns gzip on for text/html only, so without
gzip_types the JS, CSS, JSON and SVG go out full size (the main JS is
about 314 kB, about 98 kB gzipped). Check with
curl -sI -H 'Accept-Encoding: gzip' https://<site>/assets/<file>.js | grep -i content-encoding.
http2 on the listen line works on every nginx; 1.25.1 and later
also take a separate http2 on;.
Caching
/assets/(hashed build files): a year,immutable(nginx)./uploads/: 30 days,immutable(nginx). Filenames are random and never reused.- Page HTML:
no-cache(the API,routes/pages.js). The page names the build's hashed assets, so a cached old page after a deploy would ask for files that are gone. - Public API reads: 60 s, plus 5 minutes stale while revalidating
(
CACHEinserver/src/shape.js). - RSS feeds: read at most every 30 minutes; a visitor never waits for
one after the first read (
server/src/feeds.js).
The bundle
Only the home page is in the main bundle. Every other page, and the
whole admin, loads when first visited (src/App.tsx). A tab still
running an old build that asks for a page removed by a deploy reloads
once to pick up the new one.
The home page asks for events and the timeline alongside its own data
(src/pages/Home.tsx), and the server tells the browser to fetch
/api/front-page and the first hero photo while the JS downloads
(preload in server/src/pageMeta.js).
Images
Every raster upload gets a copy at most 640 px on its longer side,
<name>-640.webp, beside it in the uploads folder
(server/src/media.js). Logos, avatars and card pictures load that copy
(useSmallImage in src/lib/useSmallImage.ts) and fall back to the
full file if it's missing. The server makes any missing copies in the
background when it starts, so older uploads and files copied in by hand
get one too; deleting an upload deletes its copy.
Server
- Password checks run off the event loop (
verifyPassword, async scrypt), so a login doesn't stall other requests. - Only
/api/admin/*is logged per request; nginx's access log has the rest. - ffmpeg encodes run at
nice 19on Linux, so a clip doesn't slow the site down.