// static/service-worker.js const CACHE_NAME = "taskbot-v1-cache-v1"; const toCache = [ "/", // cache root HTML "/static/icons/icon-192.png", "/static/icons/icon-512.png", // (any CSS/JS files you serve statically, if you want them offline) ]; self.addEventListener("install", (event) => { event.waitUntil( caches.open(CACHE_NAME).then((cache) => cache.addAll(toCache)) ); }); self.addEventListener("fetch", (event) => { // Try cache first, then network event.respondWith( caches.match(event.request).then((cachedResp) => { return ( cachedResp || fetch(event.request).then((networkResp) => { // (Optionally) update the cache caches.open(CACHE_NAME).then((cache) => { cache.put(event.request, networkResp.clone()); }); return networkResp; }) ); }) ); });