1self.addEventListener('install', event => { 2 //Od razu aktywacja nowego service workera 3 self.skipWaiting(); 4}); 5 6self.addEventListener('activate', event => { 7 //Przejmij kontrolÄ nad wszystkimi klientami 8 self.clients.claim(); 9}); 10 11//self.addEventListener('fetch', event => { 12 13 14// // JeÅli to nie GET to zwrÃ³Ä fetch 15// if (event.request.method !== 'GET') { 16// event.respondWith(fetch(event.request)); 17// return; 18// } 19 20// // JeÅli to nie zasób z Azure i to z SAS (?sv= &sig=) to również zwrÃ³Ä fetch 21// const url = new URL(event.request.url); 22// if (!url.host.includes('blob.core.windows.net') || !url.href.includes("?sv=") || !url.href.includes("&sig=")) { 23// event.respondWith(fetch(event.request)); 24// return; 25// } 26 27// //console.log("session-cache : Handling fetch event for ", event.request.url); 28 29// // Zabawa z cache jeÅli to zasób, który chcemy kontrolowaÄ 30// const fetchChain = caches.open('session-cache').then(cache => { 31 32// // UsuÅ parametry po '?' z URL 33// url.search = ''; 34 35// return cache.match(url).then(response => { 36 37// // JeÅli mamy to już w cache to zwracamy 38// if (response) { 39// //console.log("session-cache > Return cached response for ", url.pathname); 40// return response; 41// } 42 43// // Nie mamy wiÄc trzeba pobraÄ z sieci 44// //console.log("session-cache > fetch from network: ", url.pathname); 45// return fetch(event.request).then(networkResponse => { 46 47// // Zapis do cache 48// //console.log("session-cache > put to cache: ", url.pathname); 49// cache.put(url, networkResponse.clone()); 50 51// // ZwrÃ³Ä zmodyfikowanÄ odpowiedź 52// return networkResponse; 53// }); 54// }); 55// }); 56 57// // Respond with the fetch chain, and in case of exception, fall back to normal fetch 58// event.respondWith( 59// fetchChain.catch(error => { 60// console.error('session-cache > Error in fetch event chain:', error); 61// return fetch(event.request); 62// }) 63// ); 64//}); 65 66 67 68 69 70self.addEventListener('fetch', event => { 71 72 73 // JeÅli to nie GET to zwrÃ³Ä fetch 74 if (event.request.method === 'GET') { 75 76 // JeÅli to nie zasób z Azure i to z SAS (?sv= &sig=) to również zwrÃ³Ä fetch 77 const url = new URL(event.request.url); 78 79 if ((url.host.includes('blob.core.windows.net') || url.href.includes("storage/sas-photo")) && !url.href.includes(".json") && url.href.includes("?sv=") && url.href.includes("&sig=")) { 80 81 //console.log("session-cache : Handling fetch event for ", event.request.url); 82 83 // Zabawa z cache jeÅli to zasób, który chcemy kontrolowaÄ 84 const fetchChain = caches.open('session-cache').then(cache => { 85 86 // UsuÅ parametry po '?' z URL 87 url.search = ''; 88 //Poprzednie skrócenie url powodowaÅo problemy z CORS jak Cropper sobie go zmieniÅ dodajÄ c jeszcze ×tamp 89 //url.search = event.request.credentials; 90 return cache.match(url).then(response => { 91 92 // JeÅli mamy to już w cache to zwracamy 93 if (response) { 94 //console.log("session-cache > Return cached response for ", url.pathname); 95 return response; 96 } 97 98 // Nie mamy wiÄc trzeba pobraÄ z sieci 99 //console.log("session-cache > fetch from network: ", url.pathname); 100 return fetch(event.request).then(networkResponse => { 101 102 // Zapis do cache 103 //console.log("session-cache > put to cache: ", url.pathname); 104 cache.put(url, networkResponse.clone()); 105 106 // ZwrÃ³Ä zmodyfikowanÄ odpowiedź 107 return networkResponse; 108 }); 109 }); 110 }); 111 112 // Respond with the fetch chain, and in case of exception, fall back to normal fetch 113 event.respondWith( 114 fetchChain.catch(error => { 115 console.error('session-cache > Error in fetch event chain:', error); 116 return fetch(event.request); 117 }) 118 ); 119 } 120 } 121 122}); 123 124 125self.addEventListener('message', async (event) => { 126 if (event.data && event.data.type === 'REMOVE_FROM_CACHE') { 127 const { cacheName, url } = event.data; 128 129 var shortUrl = new URL(url); 130 // UsuÅ parametry po '?' z URL 131 shortUrl.search = ''; 132 133 try { 134 const cache = await caches.open(cacheName); 135 const success = await cache.delete(shortUrl); 136 137 if (success) { 138 console.log(`Service Worker: Successfully removed ${shortUrl} from ${cacheName}`); 139 } else { 140 console.warn(`Service Worker: Failed to remove ${shortUrl} from ${cacheName}`); 141 } 142 } catch (error) { 143 console.error(`Service Worker: Error while removing ${shortUrl} from ${cacheName}`, error); 144 } 145 } 146});
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.