Spaces:
Sleeping
Sleeping
File size: 1,298 Bytes
391340f 709db16 8d145ad 391340f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
const CACHE = "habit-journal-v3";
const SHELL = ["/","/index.html","/manifest.webmanifest","/icons/icon-192.png","/icons/icon-512.png","/illustrations/hero-home.svg","/illustrations/pending.svg","/illustrations/scores.svg","/illustrations/coach.svg","/illustrations/empty.svg","/assets/index-Ck2YtWBn.css","/assets/index-zgsqBK9O.js","/assets/index-zgsqBK9O.js.map"];
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;
const url = new URL(request.url);
if (url.pathname.startsWith("/api/")) {
event.respondWith(fetch(request));
return;
}
if (request.mode === "navigate") {
event.respondWith(fetch(request).then(response => {
const copy = response.clone();
caches.open(CACHE).then(cache => cache.put("/index.html", copy));
return response;
}).catch(() => caches.match("/index.html")));
return;
}
event.respondWith(caches.match(request).then(hit => hit || fetch(request)));
});
|