oliver-zehentleitner / maity

performance, hub + web: static dashboard files under content-hashed URLs, cached immutable

Sign in to report

tsk-0pp41wxp6f75 Done Maity Coder Claude 003

Roadmap item 3 on tsk-a5pxwgkgr73e. Oliver (96592, 2026-11-09): focus on performance and implement the next measures.

Measured after #1518 (q8q9 96553): on a warm load, 98 of 102 dashboard files answer 304. Each 304 is still one revalidation round trip, about 100 per page (first byte 129 ms on a new connection). Signed-in pages are not faster warm: inbox and chat about 1.6 s, board 3.1 s.

Goal: a warm load asks the network for no unchanged file.

Proposal:

  • The hub serves each file under /assets/... with a content hash in the URL (for example app.<hash>.js, or ?h=<hash>), with Cache-Control: public, max-age=31536000, immutable.
  • The shell HTML (no-cache) names the hashed URLs, so a deploy changes the HTML and with it every changed file's URL.
  • An unhashed or stale URL keeps today's no-cache + ETag answer, so nothing breaks.
  • No build step: the hub computes the hashes at start-up from the files it already serves.

Step 1 (a short plan note, no code):

  • how the shell and any script that loads further files (i18n catalogs, lazy views) get the hashed names;
  • what happens during a rolling deploy (old HTML, new pod), so a mixed pair of pods never serves a missing file;
  • whether a contract sentence is needed (§16.11 / §1 caching).

I approve the plan before you build.

Boundary:

  • dashboard static files only;
  • avatars are tsk-vvyqmk9vwg8e, the API is not touched;
  • no change to the CSP beyond what the URLs need.

Measure before and after with q8q9's perf/pageload.py.

Notes

  1. Maity Coder Claude 003 · Nov 9, 2026, 07:51 UTC

    Plan, step 1 (kg22, 2026-11-09). Read against main 17fce84f (after #1518).

    Today.

    • shell.AssetFiles answers /assets/{brand,css,js,vendor}/… with no-cache and a strong content ETag (c6768529).
    • index.html names its 93 scripts and 2 stylesheets relatively under <base href="/assets/">, so it also opens from file://.
    • /assets/landing/ already does what this card asks: ?v=<digest> is answered immutable and any other request gets no-cache (landing_files.py).

    URL form: `?v=<digest>`, not a renamed file.

    • The path stays the same, so every relative URL still resolves. i18n.js builds i18n/<tag>.js from its own currentScript.src, and new URL() drops the query.
    • Fixture mode (file://) keeps the plain names, unchanged.
    • It is the same form and the same rule as /assets/landing/, and there is no build step.
    • Digest: the first 16 hex digits of the SHA-256 of the body as served, as landing_files does.

    1. How the shell and the scripts get the hashed names.

    • The shell. shell_document adds ?v= to every src/href in index.html that points into the four directories (the 93 scripts, 2 stylesheets and the icons). page_in_shell uses the same shell, so the public pages get it too.
    • CSS. app.css names its fonts (url("fonts/…woff2")) and two brand masks (url("../brand/…svg")). AssetFiles serves each stylesheet with those url()s carrying ?v=. Fonts and pictures are hashed first, so a stylesheet's digest is the digest of its rewritten body. On disk nothing changes, so file:// still works.
    • Files a script loads later. These are the i18n catalogs (js/i18n/<tag>.js), vendor/keep-the-why/* (ktw-host.js), and the brand pictures that app.js puts into <img src>.
    • The shell carries one data block, <script type="application/json" id="maity-assets">{"js/i18n/de.js":"<digest>",…}</script>, listing those three groups only (about 2 KB gzipped).
    • A JSON block is not executed, so script-src 'self' stays as it is: no CSP change.
    • A small helper M.asset(path) appends ?v= when the block names the path and returns the path unchanged otherwise (fixture mode, a file not listed).
    • i18n.js and ktw-host.js call the helper. The brand <img> in app.js may call it too or stay no-cache: two small SVGs.
    • When it is computed. At start-up, the hub walks the four directories once (about 700 KB) and keeps a digest per path. Every answer is still checked against the current body (asset_form, which reads the file again when its time or size moves). So a file edited on a running dev hub is never marked immutable under a digest it no longer has.
  2. Maity Coder Claude 003 · Nov 9, 2026, 07:51 UTC

    Plan, step 1, part 2 (kg22).

    2. Rolling deploy (old HTML, new pod).

    • helm runs maxSurge 1, maxUnavailable 0, so two pods with different files serve side by side for a while.
    • The rule: ?v= equal to the digest of the body this pod would send gets public, max-age=31536000, immutable. Any other request (another digest, none, a stale link) gets today's answer: the current file, no-cache, its ETag, 304 on a match.
    • So an immutable answer always holds exactly the bytes its URL names. A pod can never pin a wrong file in a browser or a shared cache.
    • Mixed pair, both ways:
    • New HTML asks an old pod for app.js?v=<new>: the old pod sends its own file no-cache.
    • Old HTML asks a new pod: the same, the other way round.
    • In both cases that one load may run old and new scripts together. It can happen today too, so this is no worse, and nothing stays stuck: the no-cache copy is revalidated on the next use and the new pod's ETag differs.
    • A 404 for an unknown digest would be worse (a missing script), so that is rejected. I would not add session affinity for this.
    • The gzip form keeps its own ETag (<digest>-gzip) and Vary: Accept-Encoding, as in #1518.

    3. Contract. Yes, a sentence is needed.

    • §16.11 promises no-cache plus an ETag for /assets/. It becomes: a request whose ?v= is the digest of the current file is answered immutable; any other is answered as today.
    • The shell names its files with ?v=, and the data block with its id maity-assets is part of the shell.
    • §1, in the caching list, gets the same sentence.
    • serving.md c6768529 says "Revisit when: the shell names its files by digest". A new record supersedes its "Rejected alternatives: versioned names" item and gives the reason (the measured 304s).

    Expected effect. A warm load sends no request for an unchanged file. What remains is the shell (no-cache), the API calls and, if not listed, the two brand SVGs. That is down from about 100 revalidations.

    Measuring. Before and after with q8q9's perf/pageload.py (it is not in the repo; I will ask q8q9 where it is): warm loads of inbox, chat and board, number of requests, time to first render.

    Files.

    • hub/src/maity_hub/shell.py, docs/api.md §1 and §16.11, hub/context/serving.md (new record plus an index line), hub/tests/test_app.py.
    • web/js/i18n.js and web/js/ktw-host.js (helper calls), a new helper (web/js/assets.js, or inside an existing file), and a smoke case.
    • A changelog fragment.

    Overlap on main today: #1530 (web/js/i18n.js), #1422 (web/index.html; I only read it, the hub rewrites the shell when serving), #1534 (mine, serving.md).

    PR cut. I propose one PR: contract plus hub plus the small web helper, because the contract sentence and the code have to land together. If you want the contract first, as on tsk-zp0vqj9wm37x, say so and I will split it.

    Not in scope. Avatars (tsk-vvyqmk9vwg8e), the API, CSP rules, and /assets/landing/ (already versioned).

  3. Lotse · Nov 12, 2026, 15:21 UTC

    Owner decision 2026-11-12 (req-mp3sfjnnvxrh, option 1, replaces req-jjqtn71qaa90): yes, dashboard files under ?v=<content hash> are served public, max-age=31536000, immutable; requests without a matching hash stay no-cache + ETag (option A). #1543 may go ahead as written.