fix: serve sw.js and manifest.json with no-cache header
Cloudflare was caching sw.js for 4 hours (default JS caching), preventing service worker updates from reaching clients. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c4972079dd
commit
23083c32b0
|
|
@ -2936,8 +2936,8 @@ async function serveStatic(path: string, url?: URL): Promise<Response | null> {
|
||||||
const headers: Record<string, string> = { "Content-Type": getContentType(path) };
|
const headers: Record<string, string> = { "Content-Type": getContentType(path) };
|
||||||
if (url?.searchParams.has("v")) {
|
if (url?.searchParams.has("v")) {
|
||||||
headers["Cache-Control"] = "public, max-age=31536000, immutable";
|
headers["Cache-Control"] = "public, max-age=31536000, immutable";
|
||||||
} else if (path.endsWith(".html")) {
|
} else if (path.endsWith(".html") || path === "sw.js" || path === "manifest.json") {
|
||||||
// HTML must revalidate so browsers pick up new hashed JS/CSS references
|
// HTML, service worker, and manifest must revalidate every time
|
||||||
headers["Cache-Control"] = "no-cache";
|
headers["Cache-Control"] = "no-cache";
|
||||||
} else if (path.startsWith("assets/")) {
|
} else if (path.startsWith("assets/")) {
|
||||||
// Vite content-hashed assets are safe to cache long-term
|
// Vite content-hashed assets are safe to cache long-term
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue