1const CACHE_NAME = 'jurisnet-v1.8'; 2const OFFLINE_URL = '/offline'; // Opcional: página de offline personalizada 3 4self.addEventListener('install', (event) => { 5 event.waitUntil( 6 caches.open(CACHE_NAME).then((cache) => { 7 return cache.addAll([ 8 '/', 9 '/manifest.json', 10 '/globals.css', 11 '/images/favicon.png', 12 '/images/logo_principal_positivo_800x400.png', 13 'https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined', 14 ]).catch(err => console.error('Cache init error', err)); 15 }) 16 ); 17 self.skipWaiting(); 18}); 19 20self.addEventListener('activate', (event) => { 21 event.waitUntil( 22 caches.keys().then((cacheNames) => { 23 return Promise.all( 24 cacheNames.map((name) => { 25 if (name !== CACHE_NAME) { 26 return caches.delete(name); 27 } 28 }) 29 ); 30 }) 31 ); 32}); 33 34self.addEventListener('fetch', (event) => { 35 // Ignorar chamadas de API ou de terceiros (Opcional, pode ajustar conforme necessário) 36 if (event.request.mode === 'navigate') { 37 event.respondWith( 38 fetch(event.request).catch(() => { 39 return caches.match(event.request) || caches.match('/'); 40 }) 41 ); 42 return; 43 } 44 45 // Estratégia Stale-While-Revalidate para o resto 46 event.respondWith( 47 caches.match(event.request).then((cachedResponse) => { 48 const fetchPromise = fetch(event.request).then((networkResponse) => { 49 caches.open(CACHE_NAME).then((cache) => { 50 cache.put(event.request, networkResponse.clone()); 51 }); 52 return networkResponse; 53 }); 54 return cachedResponse || fetchPromise; 55 }) 56 ); 57});
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.