1const CACHE_NAME = "alagoas-alerta-static-v2"; 2const CORE_ASSETS = ["/assets/favicon.png", "/assets/logo-alerta.png", "/manifest.webmanifest"]; 3 4self.addEventListener("install", (event) => { 5 event.waitUntil( 6 caches.open(CACHE_NAME).then((cache) => cache.addAll(CORE_ASSETS)), 7 ); 8 self.skipWaiting(); 9}); 10 11self.addEventListener("activate", (event) => { 12 event.waitUntil( 13 caches 14 .keys() 15 .then((keys) => 16 Promise.all( 17 keys 18 .filter((key) => key !== CACHE_NAME) 19 .map((key) => caches.delete(key)), 20 ), 21 ), 22 ); 23 self.clients.claim(); 24}); 25 26self.addEventListener("fetch", (event) => { 27 if (event.request.method !== "GET") return; 28 const url = new URL(event.request.url); 29 if (url.origin !== self.location.origin) return; 30 if (event.request.mode === "navigate" || event.request.destination === "document") return; 31 if (url.pathname.startsWith("/api/") || url.searchParams.has("_rsc")) return; 32 33 const isPublicAsset = url.pathname.startsWith("/assets/") || url.pathname === "/manifest.webmanifest"; 34 // Next.js already fingerprints production assets. Intercepting these files 35 // breaks Turbopack in development because chunk URLs can be reused after a 36 // code change, leaving the browser with incompatible cached JavaScript. 37 if (url.pathname.startsWith("/_next/")) return; 38 if (!isPublicAsset) return; 39 40 event.respondWith(caches.open(CACHE_NAME).then(async (cache) => { 41 const cached = await cache.match(event.request); 42 43 const networkRequest = fetch(event.request).then((response) => { 44 if (response.ok) cache.put(event.request, response.clone()); 45 return response; 46 }); 47 return cached || networkRequest; 48 })); 49});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.