Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions frontend/public/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
*/

// Cache versioning - increment to invalidate all caches
const CACHE_VERSION = 3;
const CACHE_VERSION = 4;
const CACHE_PREFIX = "know-india";

const CACHE_NAME = `${CACHE_PREFIX}-cache-v${CACHE_VERSION}`;
const IMAGE_CACHE_NAME = `${CACHE_PREFIX}-images-v${CACHE_VERSION}`;
const API_CACHE_NAME = `${CACHE_PREFIX}-api-v${CACHE_VERSION}`;
const CURRENT_CACHES = [CACHE_NAME, IMAGE_CACHE_NAME, API_CACHE_NAME];

// Static assets to cache on install
// Static assets to cache on install (exclude / and index.html so deploys always get fresh HTML)
const STATIC_ASSETS = [
"/",
"/index.html",
"/offline.html",
"/manifest.json",
"/logo192.png",
Expand Down Expand Up @@ -111,7 +109,17 @@ self.addEventListener("fetch", (event) => {
return;
}

// Other requests - network first
// HTML / navigation - network only, never cache (avoids white page after deploy)
if (isNavigationRequest(request) || url.pathname === "/" || url.pathname === "/index.html") {
event.respondWith(
fetch(request)
.then((response) => response)
.catch(() => caches.match("/offline.html"))
);
return;
}

// Other requests (JS, CSS, etc.) - network first, then cache
event.respondWith(
fetch(request)
.then((response) => {
Expand Down
6 changes: 4 additions & 2 deletions frontend/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"buildCommand": "npm run build",
"outputDirectory": "build",
"framework": "create-react-app",
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }],
"headers": [
{ "source": "/index.html", "headers": [{ "key": "Cache-Control", "value": "no-cache, no-store, must-revalidate" }] },
{ "source": "/", "headers": [{ "key": "Cache-Control", "value": "no-cache, no-store, must-revalidate" }] }
]
}
Loading