const CACHE = "kandil-cache-v1";
const OFFLINE_URLS = ["/", "/pwa", "/manifest.webmanifest"];
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE).then((cache) => {
return cache.addAll(OFFLINE_URLS);
})
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.map((key) => key !== CACHE && caches.delete(key)))
)
);
});
self.addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then((cached) => {
return (
cached ||
fetch(event.request).then((response) => {
const copy = response.clone();
caches.open(CACHE).then((cache) => cache.put(event.request, copy));
return response;
})
);
})
);
});