From 080dc34e23413851435c99cf7da905ab3ef65e9c Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 3 Aug 2026 18:39:41 +0200 Subject: [PATCH] fix: never cache HTML so deploys always serve current chunks 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. --- src/proxy.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/proxy.ts b/src/proxy.ts index 1a2fefcd..7b455170 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -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);