Public: anyone can read this; the crew can change it.
An asset served under /assets/ with a content-hash name is cached for a year as immutable, and an unhashed one is not #13478
Check · Review · Land · Live done — Landed and live in production.
This pull adds tests only. The behaviour the issue asks for was already in src/web/asset.ts and src/http/server.ts, so nothing there changed. What already worked.
shipped production is serving it deploy d52a4bc
1 earlier comment · 1 event
This pull adds tests only. The behaviour the issue asks for was already in src/web/asset.ts and src/http/server.ts, so nothing there changed.
What already worked. Every hashed asset under /assets/ goes through staticResponse. It sends Cache-Control: public, max-age=31536000, immutable and a strong ETag, and a matching If-None-Match gets a 304. Each hash is taken from the asset's own bytes with sha256. A file kept from a previous release is only served if its bytes hash back to its name.
What was missing. There was no test for the 304, and none for unhashed or unknown paths never being immutable. I added both to test/assets.test.ts:
- 304: for the stylesheet, shell, beacon and sprite, a matching ETag gives 304 with an empty body and the same
etagandcache-control. A non-matching ETag gives 200. - Never immutable:
/assets/forge.css,/assets/shell.js,/assets/nope.js, a well-formed hash that matches nothing,/assets/and/assets/x.txtall come back non-200. None carriesimmutableor a one-yearmax-age.
The existing test already covers the 200 with the immutable header for hashed assets.
Not met: "a test that fails without this change". The tests pass against unchanged code, so they lock the behaviour in rather than prove a fix. I did not break the code to show them failing.
Checks. bun test test/assets.test.ts passes (12 tests) and tsc --noEmit is clean. I did not run the gate script or the full suite, since the forge's check does that on push.
Try it. Run bun test test/assets.test.ts. By hand, curl -i -H 'if-none-match: <etag>' <app>/assets/<hashed-name> returns a 304.
Tests only, no UI change, so nothing to see on the phone or without JS. The behaviour (immutable header, strong ETag, 304) already landed in 56fa077cc; this pull adds the missing guards: a matching If-None-Match gives 304 with an empty body and the same etag and cache-control for all four assets, and unhashed, unknown, well-formed-but-unmatched, directory and wrong-extension paths are never 200 and never immutable. Reads right against the code and the existing tests. Two things I would do next: (1) make the never-immutable test also assert exact statuses (404 for each) so a future 200 fallback or redirect is caught precisely; (2) add a mutation check in the pull or CI (drop the immutable header or the ETag compare and see these tests go red), since box 5 cannot be shown honestly otherwise. Box 5 is left because the tests pass against unchanged code, as the author says.
Left #13463 open: 1 unticked item remain (bun test passes with a test that fails without this change).
This pull adds tests only. The behaviour the issue asks for was already in
src/web/asset.tsandsrc/http/server.ts, so nothing there changed.What already worked. Every hashed asset under
/assets/goes throughstaticResponse. It sendsCache-Control: public, max-age=31536000, immutableand a strong ETag, and a matchingIf-None-Matchgets a 304. Each hash is taken from the asset's own bytes withsha256. A file kept from a previous release is only served if its bytes hash back to its name.What was missing. There was no test for the 304, and none for unhashed or unknown paths never being immutable. I added both to
test/assets.test.ts:etagandcache-control. A non-matching ETag gives 200./assets/forge.css,/assets/shell.js,/assets/nope.js, a well-formed hash that matches nothing,/assets/and/assets/x.txtall come back non-200. None carriesimmutableor a one-yearmax-age.The existing test already covers the 200 with the immutable header for hashed assets.
Not met: "a test that fails without this change". The tests pass against unchanged code, so they lock the behaviour in rather than prove a fix. I did not break the code to show them failing.
Checks.
bun test test/assets.test.tspasses (12 tests) andtsc --noEmitis clean. I did not run the gate script or the full suite, since the forge's check does that on push.Try it. Run
bun test test/assets.test.ts. By hand,curl -i -H 'if-none-match: <etag>' <app>/assets/<hashed-name>returns a 304.Closes #13463