const CACHE = "taskboard-v1"; const SHELL = ["./", "index.html", "manifest.webmanifest", "icon-192.png", "icon-512.png", "apple-touch-icon.png"]; self.addEventListener("install", (e) => { e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting())); }); self.addEventListener("activate", (e) => { e.waitUntil( caches.keys() // Only this app's caches: every app on kburchtree.cloud shares one cache store. .then((keys) => Promise.all(keys.filter((k) => k.startsWith("taskboard-") && k !== CACHE).map((k) => caches.delete(k)))) .then(() => self.clients.claim()) ); }); // Network-first for same-origin shell so updates show up; cache fallback offline. // GitHub API calls pass through untouched. self.addEventListener("fetch", (e) => { const url = new URL(e.request.url); if (url.origin !== location.origin || e.request.method !== "GET") return; e.respondWith( fetch(e.request) .then((res) => { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(e.request, copy)); return res; }) .catch(() => caches.match(e.request, { ignoreSearch: true })) ); });