fix: add Cache-Control no-cache for index.html to prevent stale JS bundles
This commit is contained in:
+5
-2
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user