NGU-Web/docs/performance.md
Aidan Dona f1a0b06ac2 Page management, step 3: section types with their own settings; the front page as sections
Migration 083 gives the section types that need more than blocks their
own tables (hero, slides, countdown, stats, paths, featured cards, the
Community blog's slots, pinned posts and feeds) and turns the front page
into Home's sections: the hero, then its bands in order. Any section can
be hidden. The Front page editor, its tables and the Community page's
are gone; /api/front-page and /api/community-blog fold into the page's
sections (sectionData.js). The admin engine reads and writes a child
collection's own side tables and gated nested collections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 00:34:56 -05:00

2.5 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 (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

Every page, the front page included, 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 server tells the browser to fetch the front page's data (/api/site-pages/home) and its hero's first 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 19 on Linux, so a clip doesn't slow the site down.