24 lines
657 B
JavaScript
24 lines
657 B
JavaScript
const CACHE = "fantabeto-v2";
|
|
const ASSETS = ["/", "/index.html", "/app.js", "/styles.css", "/manifest.json"];
|
|
|
|
self.addEventListener("install", (e) => {
|
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(ASSETS)));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (e) => {
|
|
e.waitUntil(
|
|
caches.keys().then((keys) =>
|
|
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
|
)
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener("fetch", (e) => {
|
|
if (e.request.url.includes("/api/")) return; // bypass cache for API
|
|
e.respondWith(
|
|
caches.match(e.request).then((r) => r || fetch(e.request))
|
|
);
|
|
});
|