1const SOL_CACHE = 'skionline-pl-v15'; 2 3const SOL_FILES = [ 4 '/styl.css?v=15', 5 '/inne/js/skrypty.js?v=15', 6 '/inne/js/skrypty_new.js?v=15', 7 '/inne/errors/offline-skionline-pl.html', 8 '/images/logo-skionline-pl.png' 9]; 10 11self.addEventListener('install', event => { 12 self.skipWaiting(); 13 event.waitUntil( 14 caches.open(SOL_CACHE).then(cache => cache.addAll(SOL_FILES)) 15 ); 16}); 17 18self.addEventListener('activate', event => { 19 event.waitUntil( 20 caches.keys().then(names => { 21 const oldCaches = names 22 .filter(name => name !== SOL_CACHE) 23 .map(name => caches.delete(name)); 24 25 return Promise.all([ 26 self.clients.claim(), 27 ...oldCaches 28 ]); 29 }) 30 ); 31}); 32 33self.addEventListener('fetch', event => { 34 35 const request = event.request; 36 const url = new URL(request.url); 37 38 if (url.pathname.startsWith('/inne/narzedzia/') || url.pathname.startsWith('/_administracja/')) { 39 return; 40 } 41 42 if (request.method !== 'GET') return; 43 if (url.protocol !== 'http:' && url.protocol !== 'https:') return; 44 if (url.origin !== self.location.origin) return; 45 if (url.pathname.endsWith('.php')) return; 46 47 const isHTML = request.headers.get('accept')?.includes('text/html'); 48 const isAjax = request.headers.get('x-requested-with') === 'XMLHttpRequest'; 49 50 if (isHTML || isAjax) { 51 event.respondWith( 52 fetch(request).catch(async () => { 53 const cache = await caches.match('/inne/errors/offline-skionline-pl.html'); 54 return cache || new Response('Offline', { status: 503 }); 55 }) 56 ); 57 return; 58 } 59 60 event.respondWith( 61 caches.match(request).then(cacheResponse => { 62 63 const fetchPromise = fetch(request).then(networkResponse => { 64 65 if (!networkResponse) { 66 return new Response('', { status: 502 }); 67 } 68 69 if (networkResponse.status !== 200) { 70 return networkResponse; 71 } 72 73 const responseClone = networkResponse.clone(); 74 75 caches.open(SOL_CACHE).then(cache => { 76 cache.put(request, responseClone); 77 }); 78 79 return networkResponse; 80 81 }).catch(() => { 82 return cacheResponse || new Response('', { status: 504 }); 83 }); 84 85 return cacheResponse || fetchPromise; 86 }) 87 ); 88});
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.