1"use strict"; 2 3var versionNumber = 1787220051773; /* eslint-disable */ 4 5const searchParams = new URLSearchParams(self.location.search); 6const RESOURCES_PATH = searchParams.get('resourcesPath') || 'prod'; 7importScripts(`/resources/${RESOURCES_PATH}/scripts/workbox-sw.js`); 8const debug = false; // set to true when debugging to display console.logs 9 10const pulseCaches = ['resources', 'fonts', 'content-pages', 's3-photos'].map(name => `${name}-cache-${versionNumber}`); 11if (debug) console.log('build version number ' + versionNumber); 12 13// Cache resources 14const resourceRegex = new RegExp("^.*\/resources\/" + RESOURCES_PATH + "\/.*\.(?:css|js|png|jpg|jpeg|svg)"); 15workbox.routing.registerRoute(resourceRegex, 16// Use cache but fallback to network if not available 17workbox.strategies.cacheFirst({ 18 cacheName: 'resources-cache-' + versionNumber, 19 plugins: [new workbox.expiration.ExpirationPlugin({ 20 // Cache only 250 files 21 maxEntries: 250, 22 // Cache for a maximum of 2 weeks 23 maxAgeSeconds: 14 * 24 * 60 * 60 24 })] 25})); 26 27// Cache fonts 28const fontRegex = new RegExp("^.*\/resources\/" + RESOURCES_PATH + "\/.*\.(?:eot|woff|woff2)/"); 29workbox.routing.registerRoute(fontRegex, 30// Use cache but fallback to network if not available 31workbox.strategies.cacheFirst({ 32 cacheName: 'fonts-cache-' + versionNumber, 33 plugins: [new workbox.expiration.ExpirationPlugin({ 34 // Cache for a maximum of 3 months 35 maxAgeSeconds: 3 * 30 * 24 * 60 * 60 36 })] 37})); 38 39// caches all content pages with network first strategy 40workbox.routing.registerRoute(/\/(?:en|es|ca|fr|ja)\//, workbox.strategies.networkFirst({ 41 cacheName: 'content-pages-cache-' + versionNumber, 42 plugins: [new workbox.expiration.ExpirationPlugin({ 43 // Cache only 200 pages 44 maxEntries: 200, 45 // Cache for a maximum of 3 days 46 maxAgeSeconds: 3 * 24 * 60 * 60 47 })] 48})); 49 50// caches all photos from S3 51workbox.routing.registerRoute(/https:\/\/fcbarcelona-static-files\.s3\.amazonaws\.com\/.*\.(?:png|jpg|jpeg)/, 52// Use cache but fallback to network if not available 53workbox.strategies.cacheFirst({ 54 cacheName: 's3-photos-cache-' + versionNumber, 55 plugins: [new workbox.expiration.ExpirationPlugin({ 56 // Cache only 150 photos 57 maxEntries: 200, 58 // Cache for a maximum of 1 week 59 maxAgeSeconds: 7 * 24 * 60 * 60 60 })] 61})); 62self.addEventListener('install', event => { 63 if (debug) console.log('installed version ' + versionNumber + ' ...'); 64 event.waitUntil(caches.keys().then(cacheNames => { 65 if (debug) console.log('deleting old caches ...'); 66 return Promise.all(cacheNames.filter(cacheName => { 67 if (debug) console.log('deleting ...', cacheName, pulseCaches.indexOf(cacheName) < 0); 68 return pulseCaches.indexOf(cacheName) < 0; 69 }).map(cacheName => { 70 return caches.delete(cacheName); 71 })).then(self.skipWaiting); 72 })); 73}); 74self.addEventListener('activate', () => { 75 if (debug) console.log('activated version ' + versionNumber + '!'); 76});
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.