Jetzt/Topbar und Material-Routing, Pause bei Filament-Ende, Druckbericht mit Stromanteilen, Design- und Kamera-Stream-Polish; Bedarf-Alert-Spam und Platte-belegt-Bugs behoben.
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/* Nur Static-Assets cachen — nie HTML-Navigation abfangen (sonst falsche Seite in Chrome). */
|
|
const CACHE = "grotti-shell-v3";
|
|
|
|
self.addEventListener("install", (event) => {
|
|
self.skipWaiting();
|
|
event.waitUntil(
|
|
caches.open(CACHE).then((cache) =>
|
|
cache.addAll([
|
|
"/static/grotti.css?v=62",
|
|
"/static/api.js?v=32",
|
|
"/static/ui.js?v=5",
|
|
"/static/icons.svg",
|
|
"/static/fonts/InterVariable.woff2",
|
|
]).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))
|
|
);
|
|
});
|