# 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`): ```nginx 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:///assets/.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 (`CACHE` in `server/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, `-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 19` on Linux, so a clip doesn't slow the site down.