Bedarf in Sidebar/Material, Drucker-Zeitfenster und Tarif in Einstellungen, helles Theme; Legacy-Token und /api/drucker entfernt; SSE/SW-Fixes gegen hängende Navigation in Chrome.
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
/* Nur Static-Assets cachen — nie HTML-Navigation abfangen (sonst falsche Seite in Chrome). */
|
|
const CACHE = "grotti-shell-v2";
|
|
|
|
self.addEventListener("install", (event) => {
|
|
self.skipWaiting();
|
|
event.waitUntil(
|
|
caches.open(CACHE).then((cache) =>
|
|
cache.addAll([
|
|
"/static/grotti.css?v=56",
|
|
"/static/api.js?v=29",
|
|
"/static/ui.js?v=3",
|
|
]).catch(() => undefined)
|
|
)
|
|
);
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) =>
|
|
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
|
).then(() => self.clients.claim())
|
|
);
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const req = event.request;
|
|
if (req.method !== "GET") return;
|
|
// Dokument-Navigation immer ans Netz — kein Fallback auf „/“.
|
|
if (req.mode === "navigate") return;
|
|
const url = new URL(req.url);
|
|
if (url.origin !== self.location.origin) return;
|
|
if (url.pathname.startsWith("/api/")) return;
|
|
if (!url.pathname.startsWith("/static/")) return;
|
|
|
|
event.respondWith(
|
|
fetch(req)
|
|
.then((res) => {
|
|
if (res.ok) {
|
|
const copy = res.clone();
|
|
caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {});
|
|
}
|
|
return res;
|
|
})
|
|
.catch(() => caches.match(req))
|
|
);
|
|
});
|