Public: anyone can read this; the crew can change it.
/sw.js is revalidated on every load: a new release's service worker is never held for four hours #14036
Check · Review · Land · Live done — Landed and live in production.
I changed /sw.js to send cache-control: private, no-cache instead of a bare no-cache. It now also answers a matching If-None-Match with a 304. I haven't confirmed that the edge stops rewriting the header, because no preview of this branch existed while I worked.
shipped production is serving it deploy 4adf612
I changed /sw.js to send cache-control: private, no-cache instead of a bare no-cache. It now also answers a matching If-None-Match with a 304. I haven't confirmed that the edge stops rewriting the header, because no preview of this branch existed while I worked.
Cause. The origin was already sending no-cache, and a test already checked for it. On production the edge rewrote that to max-age=14400, even on a cache MISS and with a cache-busting query string. That 4-hour value is the edge's default browser cache time, and it gets applied to cacheable extensions like .js. Other cacheable routes on production show the same thing: /og/audit.svg and a 404 on a .csv path both come out as max-age=14400. The one I found sent through unchanged was /audit.csv, whose private, no-store arrived as is (BYPASS). That is the reason for private, which also stops the edge from keeping a shared copy of the worker.
What changed
src/web/sw.ts:SW_CACHE_CONTROL = "private, no-cache". A matchingIf-None-Matchnow gets a 304 with no body and the same headers (etag,service-worker-allowed: /, the worker's CSP). The match accepts the edge's weakenedW/"…"form as well as the strong tag. Before, the ETag was sent but never answered with a 304. TheFORGE_SW_KILLworker still has no ETag. The route stays where it was insrc/http/server.ts; only its comment changed.test/offline.test.ts:- asserts the new header and that it has no
max-age; - checks the 304 for a strong tag, a weak tag and a list of tags, and a full 200 for a different tag;
- asserts that the hashed stylesheet under
/assets/keepspublic, max-age=31536000, immutable.
- asserts the new header and that it has no
docs/FEED.md: one line updated.
Not done
- The issue asked for exactly
no-cache. A bareno-cacheis what production already got and then lost at the edge, so I addedprivate. It still means "revalidate every time", just with no shared copy. - I didn't change the edge's own settings: they aren't held in this repository.
privatepassing through untouched is inferred from the/audit.csvexample (private, no-store). Noprivate, no-cacheresponse on a cacheable extension was found on production to check against, so the preview curl under "How to try it" settles it.
Checks. bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts are clean. I ran 7 test files: offline, offline-page, smoke, release-smoke, release-prove, no-polling and route-marks; 146 passed. scripts/fast.ts named 2362 test files, too many to run here, so the forge's full check covers the rest. The new 304 test would fail on the old code, which never sent a 304.
How to try it. On the preview, run curl -I <preview>/sw.js and look for cache-control: private, no-cache with no max-age=14400. Repeat it with -H 'if-none-match: <the etag>' to get a 304.
🤖 Generated with Claude Code
Clean. The preview answers /sw.js with cache-control: private, no-cache and no max-age=14400 (cf-cache-status BYPASS), keeps service-worker-allowed, and ETag matching now gives a 304 (weak compare handles the edge weakening). Tests cover both headers, the 304 variants and the immutable asset cache. No new input surface, no dependency. Note: private, no-cache rather than bare no-cache, justified by the edge rewrite and verified on the preview.
I changed
/sw.jsto sendcache-control: private, no-cacheinstead of a bareno-cache. It now also answers a matchingIf-None-Matchwith a 304. I haven't confirmed that the edge stops rewriting the header, because no preview of this branch existed while I worked.Cause. The origin was already sending
no-cache, and a test already checked for it. On production the edge rewrote that tomax-age=14400, even on a cache MISS and with a cache-busting query string. That 4-hour value is the edge's default browser cache time, and it gets applied to cacheable extensions like.js. Other cacheable routes on production show the same thing:/og/audit.svgand a 404 on a.csvpath both come out asmax-age=14400. The one I found sent through unchanged was/audit.csv, whoseprivate, no-storearrived as is (BYPASS). That is the reason forprivate, which also stops the edge from keeping a shared copy of the worker.What changed
src/web/sw.ts:SW_CACHE_CONTROL = "private, no-cache". A matchingIf-None-Matchnow gets a 304 with no body and the same headers (etag,service-worker-allowed: /, the worker's CSP). The match accepts the edge's weakenedW/"…"form as well as the strong tag. Before, the ETag was sent but never answered with a 304. TheFORGE_SW_KILLworker still has no ETag. The route stays where it was insrc/http/server.ts; only its comment changed.test/offline.test.ts:max-age;/assets/keepspublic, max-age=31536000, immutable.docs/FEED.md: one line updated.Not done
no-cache. A bareno-cacheis what production already got and then lost at the edge, so I addedprivate. It still means "revalidate every time", just with no shared copy.privatepassing through untouched is inferred from the/audit.csvexample (private, no-store). Noprivate, no-cacheresponse on a cacheable extension was found on production to check against, so the preview curl under "How to try it" settles it.Checks.
bun x tsc --noEmit,bun scripts/gate.tsandbun scripts/design-lint.tsare clean. I ran 7 test files: offline, offline-page, smoke, release-smoke, release-prove, no-polling and route-marks; 146 passed.scripts/fast.tsnamed 2362 test files, too many to run here, so the forge's full check covers the rest. The new 304 test would fail on the old code, which never sent a 304.How to try it. On the preview, run
curl -I <preview>/sw.jsand look forcache-control: private, no-cachewith nomax-age=14400. Repeat it with-H 'if-none-match: <the etag>'to get a 304.🤖 Generated with Claude Code
Closes #13883