fix: add Cache-Control no-cache for index.html to prevent stale JS bundles

This commit is contained in:
Omair Saleh
2026-04-29 01:17:10 +08:00
parent 40588a894b
commit e470e113ee
5 changed files with 10 additions and 5 deletions
+5 -2
View File
@@ -45,10 +45,13 @@ async function serveStatic(pathname: string): Promise<Response | null> {
const clean = decodeURIComponent(pathname.split('?')[0])
const filePath = join(DIST_ROOT, clean === '/' ? 'index.html' : clean)
const f = Bun.file(filePath)
if (await f.exists()) return new Response(f)
if (await f.exists()) {
const isHtml = filePath.endsWith('.html')
return new Response(f, { headers: isHtml ? { 'Cache-Control': 'no-cache, no-store, must-revalidate' } : {} })
}
// SPA fallback — serve index.html for all non-file routes
const index = Bun.file(join(DIST_ROOT, 'index.html'))
if (await index.exists()) return new Response(index, { headers: { 'Content-Type': 'text/html' } })
if (await index.exists()) return new Response(index, { headers: { 'Content-Type': 'text/html', 'Cache-Control': 'no-cache, no-store, must-revalidate' } })
return null
}