oliver-zehentleitner / maity

performance: the dashboard's static files are revalidated (no-cache + ETag) instead of no-store

Sign in to report

tsk-pcw785rhymyg Done An agent

Owner decision (Oliver, req-s246xb6k1mpp option A, 2026-11-08): the dashboard's static files may be cached.

Today every file the hub serves for the dashboard (index.html, 93 scripts, 2 CSS, fonts; 691 KB gzip) goes out with cache-control: no-store — the middleware default recorded in hub/context/images.md (96d70040: "no-store unless listed"). Every reload fetches all 97 again (eyq5, tsk-fxjtwmkc4md5).

Task:

  1. Plan note first: which paths (web/js, web/css, fonts, /assets/), the exact headers (Cache-Control: no-cache + strong ETag, 304 on If-None-Match; or versioned names + long max-age if that is cleaner — say why), what stays no-store (every API answer with private data, index.html if it embeds anything per user), and how a deploy reaches browsers at once.
  2. Update the recorded rule (context entry with the reason: owner decision, files hold no private data).
  3. Tests: 304 on a matching ETag, 200 with body after a change, API routes still no-store.

Boundary: static dashboard files only; no API answer becomes cacheable in this card; no contract change (if one is needed, stop and tell me). The PR watch design (tsk-rhgzcjqcfb9s) waits for Oliver; r6fe still comes after #1509 — this card goes before r6fe.

Notes

  1. An agent · Nov 8, 2026, 17:19 UTC

    Plan: the dashboard's static files are revalidated, not `no-store` (maity-coder-claude-001#hrjz; main 4564ec5259e980daed00588c544f6c109e205a2e; req-s246xb6k1mpp A)

    A contract sentence is needed first, so I stop here as the Boundary says. docs/api.md §1 (:98-116) gives no-store for every response and lists the exceptions: the images, attachments, the contract, the badge, public pictures, and the app shell (no-cache). The dashboard's files under /assets/ are not on that list, and §16.11 (:18450-18470) gives caching only for /assets/landing/. Proposed sentences for Oliver:

    • §1, after "…the app shell (§16.11), which is no-cache: it holds no data and must follow a deploy": "and the dashboard's files under `/assets/` (§16.11), `no-cache` with an `ETag` of the file's content, for the same reason."
    • §16.11, after the shell's paragraph: "The dashboard's files under `/assets/` (`css/`, `js/`, `brand/`, `vendor/`) are answered `Cache-Control: no-cache` with a strong `ETag` taken from the file's content; a request whose `If-None-Match` matches gets `304` without a body."

    What exists: shell.AssetFiles (a Starlette StaticFiles over css/ js/ brand/ vendor/) already sends an ETag and answers 304. The middleware (middleware.py:563-571) then overwrites Cache-Control with no-store, because the route sets none. no-cache is already on ROUTE_CACHE. The shell is already no-cache (SHELL_HEADERS).

    Change (hub only, once the contract is in):

    1. AssetFiles answers Cache-Control: no-cache on its 200 and 304.
    2. The ETag is "<sha256 of the content, first 32 hex>", cached per process by (path, st_mtime_ns, size). This replaces Starlette's MD5 of mtime and size: an image built with normalised file times could otherwise keep the old ETag for a changed file of the same size. Last-Modified is dropped so that only the ETag decides.
    3. Unchanged:
    • every /api/v1/… answer and the 404s under /assets/ stay no-store;
    • the shell stays no-cache, since it is per request (Vary: Cookie, a public page inside it, the social image's address);
    • /assets/landing/ keeps its own rule.

    A deploy reaches browsers at once: no-cache makes the browser revalidate on every use. A changed file has a new ETag, so the answer is 200 with the new file. During a rolling update, two pods with different files give different ETags, which is also a 200.

    Gain: a reload sends the same 97 requests, but each answer is a 304 of a few hundred bytes instead of 691 KB gzip. eyq5's tsk-fxjtwmkc4md5 can measure it before and after.

    Versioned names with a long max-age (not this card): the hub would rewrite the shell's 93 <script src> and 2 <link href> to ?v=<digest> and answer them immutable, as /assets/landing/ already does. A reload would then send no requests for them. That is cleaner for speed, but it needs a rewrite in shell_document, has to leave url() references inside the CSS on no-cache, and is also a contract change. I propose it as a follow-up card once this one's numbers are in.

    Context: update 96d70040 (images.md) with the new exception, plus a new entry in hub/context/ with the reason (the owner's decision, and the files hold no private data) and the rejected alternatives: Starlette's mtime ETag, and versioned names for now.

    Tests:

    • 200 with no-cache and an ETag, then 304 on a matching If-None-Match.
    • Same size and same mtime with changed content gives a new ETag and a 200 with the body.
    • /api/v1/… stays no-store, as do a 404 under /assets/ and /assets/landing/ unchanged.
    • The shell is unchanged.

    There is also a changelog fragment. No migration.