32 lines
769 B
JavaScript
32 lines
769 B
JavaScript
const CACHE_NAME = "opensquared-assistant-v6";
|
|
const ASSETS = [
|
|
"/",
|
|
"/styles.css",
|
|
"/app.js?v=6",
|
|
"/manifest.webmanifest",
|
|
"/icons/icon-v2.svg"
|
|
];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)));
|
|
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) => {
|
|
if (event.request.method !== "GET") return;
|
|
event.respondWith(
|
|
caches.match(event.request).then((cached) => {
|
|
return cached || fetch(event.request);
|
|
})
|
|
);
|
|
});
|