41 lines
999 B
JavaScript
41 lines
999 B
JavaScript
const CACHE_NAME = "adc-bestelapp-v1";
|
|
const APP_SHELL = ["/login", "/manifest.webmanifest", "/icon.svg"];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)),
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) =>
|
|
Promise.all(
|
|
keys
|
|
.filter((key) => key !== CACHE_NAME)
|
|
.map((key) => caches.delete(key)),
|
|
),
|
|
),
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const request = event.request;
|
|
const url = new URL(request.url);
|
|
|
|
if (request.method !== "GET" || url.origin !== self.location.origin) {
|
|
return;
|
|
}
|
|
|
|
// Never cache authenticated pages or API responses containing private data.
|
|
if (url.pathname === "/" || url.pathname.startsWith("/api/")) {
|
|
return;
|
|
}
|
|
|
|
event.respondWith(
|
|
fetch(request).catch(() => caches.match(request)),
|
|
);
|
|
});
|