/* KCA app-shell service worker. It caches only the static shell, never API * responses: certificate and key material must not be served stale. */ const CACHE = "kca-shell-v1"; const SHELL = ["/", "/manifest.webmanifest", "/icons/icon.svg"]; self.addEventListener("install", (event) => { event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(SHELL)).then(() => self.skipWaiting())); }); self.addEventListener("activate", (event) => { event.waitUntil( caches.keys().then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key)))) .then(() => self.clients.claim()) ); }); self.addEventListener("fetch", (event) => { const request = event.request; if (request.method !== "GET") return; const url = new URL(request.url); if (url.origin !== self.location.origin) return; if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/auth/")) return; event.respondWith( caches.match(request).then((cached) => cached || fetch(request).catch(() => caches.match("/"))) ); });