1const version = 'dev'; 2 3const offlineFiles = [ 4 // '/app/logo.svg', 5 // '/fonts/Inter-var.woff2 6]; 7 8self.addEventListener('install', function (event) { 9 event.waitUntil( 10 caches 11 .open(version + '_fundamentals') 12 .then(function (cache) { 13 return cache.addAll(offlineFiles); 14 }) 15 .then(function () { 16 return self.skipWaiting(); 17 }) 18 ); 19}); 20 21self.addEventListener('fetch', function (event) { 22 const requestUrl = event.request.url; 23 const isGetRequest = event.request.method === 'GET'; 24 25 const destination = event.request.destination; 26 const isDocument = destination === 'document'; 27 const isImage = destination === 'image' || destination === '' && requestUrl.endsWith('.svg'); 28 const isVideo = requestUrl.endsWith('.mp4'); 29 const isScript = destination === 'script'; 30 const isStyle = destination === 'style'; 31 32 const regex = /^(https|http)(:\/\/)(([a-z0-9-])+(.))?([a-z].+)?(localhost:44305)(\/)(app\/assets|media)/g; 33 const regexStaticAssets = /^(https|http)(:\/\/)(([a-z0-9-])+(.))?([a-z].+)?(localhost:44305)(\/)(app\/assets)/g; 34 35 const isAllowedUrl = requestUrl.match(regex) !== null; 36 const isStaticAsset = requestUrl.match(regexStaticAssets) !== null; 37 38 if (isGetRequest && isAllowedUrl && !isDocument) { 39 if (isScript || isStyle || (isImage && isStaticAsset)) { 40 event.respondWith( 41 caches.match(event.request).then(response => { 42 function fetchAndCache() { 43 return fetch(event.request).then(response => { 44 if (response.headers.get('Content-Length') !== '0') { 45 const cacheCopy = response.clone(); 46 let cacheLocation = version; 47 48 if (isImage) { 49 cacheLocation += '_staticAssets'; 50 } 51 52 if (isScript || isStyle) { 53 cacheLocation += '_scriptStyle'; 54 } 55 56 caches.open(cacheLocation).then(cache => cache.put(event.request, cacheCopy)); 57 } 58 return response; 59 60 }); 61 } 62 63 if (!response) { return fetchAndCache(); } 64 return response; 65 }) 66 ); 67 } 68 69 if ((isImage || isVideo) && !isStaticAsset) { 70 event.respondWith( 71 caches.match(event.request).then(response => { 72 function fetchAndCache() { 73 return fetch(event.request).then(response => { 74 if (response.headers.get('Content-Length') !== '0') { 75 const cacheCopy = response.clone(); 76 let cacheLocation = version; 77 cacheLocation += '_umbracoImages'; 78 79 caches.open(cacheLocation).then(cache => cache.put(event.request, cacheCopy)); 80 } 81 return response; 82 }); 83 } 84 85 if (!response) { return fetchAndCache(); } 86 return response; 87 }) 88 ); 89 } 90 } 91 else return; 92}); 93 94self.addEventListener('activate', function (event) { 95 event.waitUntil( 96 caches 97 .keys() 98 .then(function (keys) { 99 return Promise.all( 100 keys 101 .filter(function (key) { 102 return !key.startsWith(version); 103 }) 104 .map(function (key) { 105 return caches.delete(key); 106 }) 107 ); 108 }) 109 ); 110});
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.