Files
kleiax 904d14b64c
CI / test (push) Canceled after 0s
Initial commit
2026-09-12 22:22:17 +02:00

30 lines
1019 B
JavaScript

const CACHE_NAME = "gardomatic-shell-v9";
const APP_SHELL = [
"/static/css/main.css",
"/static/css/cropper-1.6.2.min.css",
"/static/js/htmx-2.0.10.min.js",
"/static/js/main.js",
"/static/js/cropper-1.6.2.min.js",
"/static/manifest.manifest",
"/static/icons/gardomatic-192.png",
"/static/icons/gardomatic-512.png",
"/static/offline.html",
];
self.addEventListener("install", (event) => {
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)));
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((names) => Promise.all(names.filter((name) => name !== CACHE_NAME).map((name) => caches.delete(name)))),
);
});
self.addEventListener("fetch", (event) => {
if (event.request.method !== "GET" || new URL(event.request.url).origin !== self.location.origin) {
return;
}
event.respondWith(fetch(event.request).catch(() => caches.match(event.request).then((response) => response || caches.match("/static/offline.html"))));
});