Skip to content

Make redirects no-store - #185

Merged
neuromechanist merged 1 commit into
mainfrom
fix/issue-183-redirect-no-store
Jul 25, 2026
Merged

neuromechanist merged 1 commit into
mainfrom
fix/issue-183-redirect-no-store

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #183.

Cross-host and retired-path redirects carried no Cache-Control, so a bare 301 was heuristically cacheable — and browsers cache permanent redirects aggressively and persistently.

Why it matters

Both redirect decisions encode a route classification — a deploy-time choice — not a fact about the world. When that classification changes, a cached redirect keeps sending clients to the old answer, and it lives in the one cache we can't purge.

That already happened. /api/notices was classified marketing-only and 301'd off app.nemar.org for ~20 minutes between #179 and #182. Any browser that ran the banner's fetch in that window can hold the redirect indefinitely, so the server-side fix never reaches it — the banner stays broken there until a hard reload.

Nothing user-visible resulted (the window was short and there are no notices yet), but the mechanism turns any future route reclassification into a per-user cache problem instead of a deploy.

The existing comment and test had the right intent, backwards

// No Cache-Control: browser redirect cache is plenty, and
// CDN-caching the redirect would pin clients to the wrong host if we ever
// re-balance the route split.

and a test named "doesn't set Cache-Control on cross-host redirects (deploy churn safety)" asserting the header was absent.

The hazard named there is exactly right — pinning clients through a re-balance — but omitting the header is what causes it. The comment guards the CDN and leaves the browser, which is both the likelier cache and the unpurgeable one. The test locked that in.

Change

A single NO_STORE_HEADER applied to both redirect branches. Cost is nil: empty-body responses on paths that are, by definition, being requested on the wrong host.

Applied to retired-path redirects too. Those are a genuinely permanent move so caching them is defensible — but they're low-traffic legacy links by definition, and the same "this is a deploy-time mapping" argument applies if one is ever un-retired. Not worth the asymmetry for the saving.

Testing

854 passing, 38 in middleware.test.ts (4 new/rewritten). typecheck, lint, build clean.

The old test is rewritten to assert no-store and carries the reasoning so the intent can't invert again. Added coverage for the non-GET (307) path, the retired-path branch, and that isPublicCacheable still rejects these so the edge cache keeps ignoring them.

Verified the tests actually bite: removing NO_STORE_HEADER from the cross-host branch fails 2 tests rather than passing silently.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 254085d into main Jul 25, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the fix/issue-183-redirect-no-store branch July 25, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-host 301s are browser-cacheable, pinning clients through a route reclassification

1 participant