const CACHE_NAME = "my-cache"; const OFFLINE_URL = "/static/offline.html"; self.addEventListener("install", (event) => { event.waitUntil( caches.open(CACHE_NAME).then((cache) => { return cache.addAll([ "/", "/static/css/portal.css", "/static/js/app.js", "/static/images/favicon.png", OFFLINE_URL, ]); }) ); }); self.addEventListener("fetch", (event) => { if (event.request.mode === "navigate") { event.respondWith( fetch(event.request).catch(() => { return caches.match(OFFLINE_URL); }) ); } else { event.respondWith( caches.match(event.request).then((response) => { return response || fetch(event.request); }) ); } });