1const CACHE_NAME = 'image-cache-v1'; 2const CACHE_CSS_NAME = 'css-cache-v1'; 3const CACHE_JS_NAME = 'js-cache-v1'; 4const CACHE_FONT_NAME = 'font-cache-v1'; 5 6const domainRegex = new RegExp("https:\/\/(localhost:.[0-9]+|www.feelgoodcontacts.[a-z]+|static2.feelgoodcontacts.net|static.lensgroup.co|[a-z0-9]+.lensgroup.co)\."); 7//const domainRegex = new RegExp("https:\/\/(ukwebsite.google.co)\."); 8 9self.addEventListener('fetch', (event) => { 10 //console.log('Service Worker get the reqeust', event.request); 11 // Check if the request destination is an image 12 if (domainRegex.test(event.request.url)) { 13 var cacheName = ''; 14 switch (event.request.destination) { 15 case "image": { 16 cacheName = "image-cache-v1"; 17 } 18 case "style": { 19 cacheName = "css-cache-v1"; 20 } 21 case "script": { 22 cacheName = "js-cache-v1"; 23 } 24 case "font": { 25 cacheName = "font-cache-v1"; 26 } 27 } 28 29 if (cacheName.length > 0) { 30 event.respondWith( 31 caches.match(event.request).then((cachedResponse) => { 32 // Return cached image if available 33 if (cachedResponse) { 34 return cachedResponse; 35 } 36 // Otherwise fetch from network, cache it, and return 37 return fetch(event.request).then((networkResponse) => { 38 try { 39 return caches.open(cacheName).then((cache) => { 40 cache.put(event.request, networkResponse.clone()); 41 return networkResponse; 42 }); 43 } catch (error) { 44 //Storage quota exceeded! Clearing old items or notifying user... 45 if (error.name === 'QuotaExceededError') { 46 console.error('SW Storage quota exceeded!'); 47 } else { 48 console.error('SW error! ', error); 49 } 50 return networkResponse; 51 } 52 53 }); 54 }) 55 ); 56 } 57 } 58 59});
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.