1'use strict'; 2 3const cacheVersion = '1.2.6'; 4 5importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js'); 6importScripts('https://web.webpushs.com/sp-push-worker-fb.js?ver=2.0'); 7 8if (workbox) { 9 /** 10 * Includes legacy caches so they are removed after switching 11 * from the previous Service Worker implementation. 12 */ 13 const isManagedCache = name => 14 /^(?:amp-)?(?:pages|assets|manifest|images|fonts|offline)-/.test(name); 15 16 const isAdminRequest = url => 17 /\/wp-admin(?:\/|$)|\/wp-login\.php(?:\?|$)/i.test(url.pathname); 18 19 const isAdminAsset = url => 20 /\/wp-includes\/(?:css|js)\/(?:admin-bar|dashicons|hoverintent)/i.test(url.pathname); 21 22 self.addEventListener('install', () => { 23 self.skipWaiting(); 24 }); 25 26 self.addEventListener('activate', event => { 27 event.waitUntil( 28 caches.keys() 29 .then(cacheNames => 30 Promise.all( 31 cacheNames 32 .filter(cacheName => 33 isManagedCache(cacheName) 34 && !cacheName.endsWith(`-${cacheVersion}`) 35 ) 36 .map(cacheName => caches.delete(cacheName)) 37 ) 38 ) 39 .then(() => self.clients.claim()) 40 ); 41 }); 42 43 /** 44 * Images. 45 * Front only. 46 */ 47 workbox.routing.registerRoute( 48 ({request, url}) => 49 url.origin === self.location.origin 50 && request.destination === 'image' 51 && !isAdminRequest(url) 52 && !isAdminAsset(url), 53 new workbox.strategies.CacheFirst({ 54 cacheName: `images-${cacheVersion}`, 55 plugins: [ 56 new workbox.cacheableResponse.CacheableResponsePlugin({ 57 statuses: [200], 58 }), 59 new workbox.expiration.ExpirationPlugin({ 60 maxEntries: 150, 61 maxAgeSeconds: 60 * 60 * 24 * 30, // 30 days 62 purgeOnQuotaError: true, 63 }), 64 ], 65 }) 66 ); 67 68 /** 69 * Fonts. 70 * Front only. 71 */ 72 workbox.routing.registerRoute( 73 ({request, url}) => 74 url.origin === self.location.origin 75 && request.destination === 'font' 76 && !isAdminRequest(url) 77 && !isAdminAsset(url), 78 new workbox.strategies.CacheFirst({ 79 cacheName: `fonts-${cacheVersion}`, 80 plugins: [ 81 new workbox.cacheableResponse.CacheableResponsePlugin({ 82 statuses: [200], 83 }), 84 new workbox.expiration.ExpirationPlugin({ 85 maxEntries: 30, 86 maxAgeSeconds: 60 * 60 * 24 * 30, // 30 days 87 purgeOnQuotaError: true, 88 }), 89 ], 90 }) 91 ); 92 93 /** 94 * CSS + JS. 95 * Front only. 96 */ 97 workbox.routing.registerRoute( 98 ({request, url}) => 99 url.origin === self.location.origin 100 && ['style', 'script'].includes(request.destination) 101 && !isAdminRequest(url) 102 && !isAdminAsset(url) 103 && !/\/adt-pwa-sw.*\.js$/i.test(url.pathname), 104 new workbox.strategies.CacheFirst({ 105 cacheName: `assets-${cacheVersion}`, 106 plugins: [ 107 new workbox.cacheableResponse.CacheableResponsePlugin({ 108 statuses: [200], 109 }), 110 new workbox.expiration.ExpirationPlugin({ 111 maxEntries: 120, 112 maxAgeSeconds: 60 * 60 * 24 * 7, // 7 days 113 purgeOnQuotaError: true, 114 }), 115 ], 116 }) 117 ); 118}
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.