Repository navigation
Description
What happens now
Citry serves the Events browser runtime at {prefix}/ext/events/runtime.js and the i18n runtime at {prefix}/ext/i18n/runtime.js. Neither URL contains a version, and both answer with Cache-Control: no-store. As a result:
- every page load downloads the full Events runtime again (about 400 KB, the same file as
citry.js), and the i18n runtime with it; - the browser cannot keep either file between pages.
no-store is there because the Events plan pairs a rendered page with its runtime only through that one URL (runtime-route amendment). An upgraded runtime has to reach the browser at the same URL.
During #574 we tried no-cache with an ETag, so the browser asks before each use and gets 304 while its copy is current. Review found a gap: the back and forward buttons may reuse a stored script without asking the server. Right after a deploy, a page reached that way can get new HTML with the old runtime. With security_script_integrity on, the page then fails its integrity check and never starts. So 0.7.0 keeps no-store.
Proposal
Serve each runtime from a URL that contains a hash of its bytes, for example {prefix}/ext/events/runtime.<hash>.js, with Cache-Control: public, max-age=31536000, immutable, like the Events definitions and stylesheets already are. The page links the hash of the runtime it was rendered for. Then:
- the browser keeps the runtime for a year and does not ask again on each page load (no per-use
304); - after a deploy, a new page links a new URL, so it can never run with an old runtime, on a normal load or a back/forward one;
- an old page keeps asking for its own hash.
citry.js (the dependencies runtime) serves the same bytes and also stays on no-store in 0.7.0 (#574), so it moves to the same scheme.
This reverses a plan decision
The Events plan says the runtime keeps a stable URL with no version in it ("There is no runtime query-version compatibility protocol"). This issue reverses that decision, so write a short plan before implementing it. The plan should cover:
- the URL shape, and where the page gets the hash (emission, the fragment preloader,
integrity, and preload hints all name this URL); - whether the stable URL stays as an alias (with
no-storeorno-cache) for pages and tools that hard-code it; - static export (
static_deps.py), the preview host, and the docs playground; - what moves for i18n, whose runtime has its own build ID.
Error modes the plan must state
- An old page asks for a hash that is gone. A page rendered before a deploy, or reopened from history, asks for
runtime.<old-hash>.jsafter the server only holds the new runtime. Choose one: answer404(withno-store, so the miss is not cached), and say what the page does next (it never starts; does it need a reload message?); or keep serving recent hashes for a while (how many, where they are stored, and how they are dropped across workers and restarts). - Rolling deploys. Workers on different versions answer different hashes. A page rendered by a new worker may ask an old worker for the new hash. Decide whether that is a
404, a retry, or something the shared cache covers. - A malformed or unknown hash (wrong length or characters):
404, the same as the definitions route. - A CDN in front of the app that keeps
404answers for longer than intended.
Activity
perf(deps): keep citry.js on no-store like the Events runtime
docs(design): record the maintainer's decisions on the hashed runtime…
docs(design): content-hashed URLs for the browser runtimes (#578) (#627)
docs(claude): list the runtime HEAD check, reload and CORS header in …
feat: serve the browser runtimes from content-hashed URLs (#578)
docs(claude): list the runtime HEAD check, reload and CORS header in …
refactor: report a missing runtime in the console instead of reloading (
docs(claude): keep only the CORS entry from #578 in Mechanism 7
feat: serve the browser runtimes from content-hashed URLs (#578) (#652)