SPB Git

Repository Public

sw.js 905 B 12 lines javascript

1// SP TV service worker: installability + cache of immutable build assets and icons only.2// Pages, the API and every stream always go to the network (nothing private is cached, nothing is replayed offline).3const CACHE = "sptv-static-v1";4self.addEventListener("install", () => self.skipWaiting());5self.addEventListener("activate", (e) => e.waitUntil(caches.keys().then((ks) => Promise.all(ks.filter((k) => k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim())));6self.addEventListener("fetch", (e) => {7  const u = new URL(e.request.url);8  if (e.request.method !== "GET" || u.origin !== location.origin) return;9  if (!u.pathname.startsWith("/_next/static/") && !u.pathname.startsWith("/icons/")) return;10  e.respondWith(caches.open(CACHE).then(async (c) => (await c.match(e.request)) || fetch(e.request).then((r) => { if (r.ok) c.put(e.request, r.clone()); return r; })));11});12
Files main
Menu

Theme