fix: never cache HTML so deploys always serve current chunks
CI / check (push) Successful in 30s
CI / release (push) Skipped
CI / deploy (push) Successful in 1m2s

Anonymous HTML was sent with 'public, max-age=60, s-maxage=300,
stale-while-revalidate=300'. After a rebuild the old chunk URLs (keyed by
deploy id) are deleted, so any browser/CDN holding the stale HTML got 404s
for up to five minutes. Since the deploy id is the git commit, the HTML must
be re-fetched after every deploy; only content-hashed static assets should
be cached. Return no-store for all HTML documents.
This commit is contained in:
openhands committed 2026-08-03 18:39:41 +02:00
1 parent 450e7e8d00
commit 080dc34e23
1 file changed
+8 -11
+8 -11
View File
@@ -40,17 +40,14 @@ export const proxy = async (req: import("next/server").NextRequest) => {
const response = NextResponse.next({ request: { headers } });
if (token) {
response.headers.set(
"Cache-Control",
"private, no-cache, no-store, max-age=0, must-revalidate",
);
} else {
response.headers.set(
"Cache-Control",
"public, max-age=60, s-maxage=300, stale-while-revalidate=300",
);
}
// HTML is never cached (browser/CDN/edge) so that after a deploy the page
// always references the current build's chunks. Static assets are
// content-hashed + immutable and can be cached aggressively; a stale HTML
// document would reference chunk URLs that no longer exist after a rebuild.
response.headers.set(
"Cache-Control",
"private, no-cache, no-store, max-age=0, must-revalidate",
);
for (const [key, value] of Object.entries(SECURITY_HEADERS)) {
response.headers.set(key, value);