Files
dashcaddy/status/sw.js
Sami f61e85d9a7 Initial commit: DashCaddy v1.0
Full codebase including API server (32 modules + routes), dashboard frontend,
DashCA certificate distribution, installer script, and deployment skills.
2026-03-05 02:26:12 -08:00

50 lines
1.4 KiB
JavaScript

const CACHE = "sami-cloud-dashboard-v9";
const PRECACHE = [
"index.html",
"assets/site.webmanifest",
"assets/favicon.svg",
"assets/icon-192.png",
"assets/icon-512.png",
"assets/apple-touch-icon.png",
"assets/weather/clear-day.svg",
"assets/weather/clear-night.svg",
"assets/weather/partly-cloudy-day.svg",
"assets/weather/partly-cloudy-night.svg",
"assets/weather/cloudy.svg",
"assets/weather/fog.svg",
"assets/weather/drizzle.svg",
"assets/weather/rain.svg",
"assets/weather/sleet.svg",
"assets/weather/snow.svg",
"assets/weather/thunderstorm.svg",
"assets/weather/wind.svg"
];
self.addEventListener("install", (e) => {
self.skipWaiting();
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(PRECACHE)));
});
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
).then(() => self.clients.claim())
);
});
self.addEventListener("fetch", (e) => {
const { request } = e;
const url = new URL(request.url);
if (url.origin !== location.origin) return;
// Never cache API or probe responses - always go to network
if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/probe/")) return;
e.respondWith(
fetch(request).then(resp => {
caches.open(CACHE).then(cache => cache.put(request, resp.clone())).catch(()=>{});
return resp.clone();
}).catch(() => caches.match(request))
);
});