1let app_v = '2024.0601'; 2 3/** 4 Service worker handler 5 **/ 6 7// Prepare caches 8const swCaches = { 9 'static': 'cedar_static_' + app_v , 10 'dynamic': 'cedar_dynamic_' + app_v , 11 'icons': 'cedar_icons_' + app_v 12}; 13 14// Offline page location 15const swOffline = 'Static/offline.html' ; 16const sw404 = 'Static/404.html' ; 17 18// Load workbox 19importScripts( 'https://storage.googleapis.com/workbox-cdn/releases/3.2.0/workbox-sw.js' ); 20 21if ( workbox ) { 22 23 // Cache names setup 24 workbox.core.setCacheNameDetails({ 25 prefix: 'cedar', 26 suffix: app_v 27 }) ; 28 29 // Pre-cache paths 30 // Load this up with all ststic resources that may be called on by an offline page load 31 // This should include icons etc. that are needed for hover-on effects that may not have been 32 // cached before going off-line. This list need not include icons that will definitely have been 33 // cached by an online visit, such as the CEDAR logo. 34 const precacheList = [ 35 {url: '/favicon.ico' , revision: app_v }, 36 {url: '/Static/manifest.json', revision: app_v }, 37 {url: '/Static/Icons/ui/ux2/appbar-shield-alert.png' , revision: app_v }, 38 {url: '/Static/Icons/ui/ux2/appbar-network-disconnect.png' , revision: app_v }, 39 {url: '/Static/Icons/ui/ux2/appbar-connection-quality-veryhigh.png' , revision: app_v }, 40 {url: '/Static/Icons/ui/ux2/appbar-draw-pen-add.png' , revision: app_v }, 41 {url: '/Static/Icons/ui/ux2/appbar-draw-pen-add-green.png' , revision: app_v }, 42 {url: '/Static/Icons/ui/ux2/appbar-tools.png' , revision: app_v }, 43 {url: '/Static/Icons/ui/ux2/appbar-tools-green.png' , revision: app_v }, 44 {url: '/Static/Icons/ui/ux2/appbar-home-empty.png' , revision: app_v }, 45 {url: '/Static/Icons/ui/ux2/appbar-home-empty-green.png' , revision: app_v }, 46 {url: '/Static/Icons/ui/ux2/appbar-door-leave.png' , revision: app_v }, 47 {url: '/Static/Icons/ui/ux2/appbar-door-leave-green.png' , revision: app_v }, 48 {url: '/Static/Icons/ui/ux2/appbar-magnify-green.png' , revision: app_v }, 49 {url: '/Static/Icons/ui/ux2/appbar-arrow-right.png' , revision: app_v }, 50 {url: '/Static/Images/ops_page/ajax-loader_search.gif' , revision: app_v }, 51 {url: '/Static/Images/ops_page/ajax-loader_search_alt.gif' , revision: app_v }, 52 {url: '/Static/Images/ops_page/ajax-loader_large_dial.gif' , revision: app_v }, 53 {url: '/Static/CSS/ops_auth.css' , revision: app_v }, 54 {url: '/Static/Compiled/sprite.png' , revision: app_v }, 55 {url: '/Static/Compiled/sprite.css' , revision: app_v }, 56 57 // Offline page resources 58 {url: '/Static/offline.html' , revision: app_v }, 59 {url: '/Static/Lib/jQuery/jquery-3.6.1.min.js' , revision: app_v }, 60 {url: '/Static/Lib/jQuery/jquery-migrate-3.4.1.min.js' , revision: app_v }, 61 {url: '/Static/Lib/jQuery/plugins/jquery.easing.1.4.2.min.js' , revision: app_v }, 62 {url: '/Static/CSS/ops_animations.css' , revision: app_v }, 63 {url: '/Static/CSS/ops_page.css' , revision: app_v }, 64 {url: '/Static/CSS/ops_migrate.css' , revision: app_v }, 65 {url: '/Static/Compiled/cedar.auth.min.css' , revision: app_v }, 66 {url: '/Static/Compiled/cedar.auth.min.js' , revision: app_v }, 67 {url: '/Static/Compiled/cedar.min.css' , revision: app_v }, 68 {url: '/Static/Compiled/cedar.min.js' , revision: app_v }, 69 {url: '/Static/Lib/ops_jQ/ops_offline.js' , revision: app_v }, 70 {url: '/Static/Icons/ui/ux2/appbar-check.png' , revision: app_v }, 71 {url: '/Static/Icons/ui/ux2/appbar-alert.png' , revision: app_v }, 72 {url: '/Static/Images/App/CEDAR_logo_large_white.png' , revision: app_v } , 73 {url: '/Static/Images/App/CEDAR_logo_bg_white.png' , revision: app_v } 74 ] ; 75 76 // Use the precache list to prepare resources before service-worker install 77 workbox.precaching.precacheAndRoute( 78 precacheList , 79 { 80 directoryIndex: null, 81 cleanUrls: false 82 } 83 ) ; 84 85 // Google fonts: Prioritise cache, no max, no expiry 86 workbox.routing.registerRoute( 87 new RegExp('https:\/\/fonts.(?:googleapis|gstatic).com/(.*)'), 88 workbox.strategies.cacheFirst({ 89 cacheName: swCaches.static 90 }) 91 ); 92 93 // Google visualisations and more: network first, timeout after 1 second 94 // Note: this may not actually cache anything with opaque responses. 95 workbox.routing.registerRoute( 96 new RegExp('https://www.(?:googleapis|gstatic).com\/(.*)'), 97 workbox.strategies.networkFirst({ 98 networkTimeoutSeconds: 1, 99 cacheName: swCaches.static, 100 plugins: [ 101 new workbox.expiration.Plugin({
102 // 50 maximum entries 103 maxEntries: 200, 104 // Cache for a maximum of 30 days 105 maxAgeSeconds: 30 * 24 * 60 * 60 106 }), 107 ], 108 }), 109 ); 110 111 // All CSS & JS: Prioritise cache but update in the background, expire after 30 days 112 workbox.routing.registerRoute( 113 new RegExp('\/.*(?:js|css)$'), 114 workbox.strategies.staleWhileRevalidate({ 115 cacheName: swCaches.static, 116 plugins: [ 117 new workbox.expiration.Plugin({ 118 // No maximum file count 119 // Cache for a maximum of 30 days 120 maxAgeSeconds: 30 * 24 * 60 * 60 121 }) 122 ], 123 }) 124 ); 125 126 // Audio: Prioritise cache, no maximum age or limit 127 workbox.routing.registerRoute( 128 new RegExp('.*\\/[Ss]tatic\\/[Aa]udio\\/.*\\..*'), 129 workbox.strategies.cacheFirst({ 130 cacheName: swCaches.static 131 }) 132 ); 133 134 // Icons: Prioritise cache, no maximum age or limit (small footprint) 135 workbox.routing.registerRoute( 136 new RegExp('.*\\/[Ss]tatic\\/[Ii]cons\\/.*\\.(?:png|jpg|jpeg|svg|gif)'), 137 workbox.strategies.cacheFirst({ 138 cacheName: swCaches.icons 139 }) 140 ); 141 142 // Static Images: Prioritise cache, no maximum age but limit to 35 143 workbox.routing.registerRoute( 144 new RegExp('.*\\/[Ss]tatic\\/[Ii]mages\\/.*\\.(?:png|jpg|jpeg|svg|gif)'), 145 workbox.strategies.cacheFirst({ 146 cacheName: swCaches.static, 147 plugins: [ 148 new workbox.expiration.Plugin({ 149 // No maximum file count 150 maxEntries: 35 151 }) 152 ], 153 }) 154 ); 155 156 // All other images: Prioritise cache, no maximum age but limit to 50 157 workbox.routing.registerRoute( 158 new RegExp('.*\\/public\/.*'), 159 new workbox.strategies.NetworkOnly() 160 ); 161 workbox.routing.registerRoute( 162 new RegExp('.*\\.(?:png|jpg|jpeg|svg|gif)'), 163 workbox.strategies.cacheFirst({ 164 cacheName: swCaches.static, 165 plugins: [ 166 new workbox.expiration.Plugin({ 167 // No maximum file count 168 maxEntries: 200 169 }) 170 ], 171 }) 172 ); 173 174 workbox.routing.registerRoute( 175 new RegExp('.*\\/reports\/browse\/.*'), 176 new workbox.strategies.NetworkOnly() 177 ); 178 workbox.routing.registerRoute( 179 new RegExp('.*\\/sso\/.*'), 180 new workbox.strategies.NetworkOnly() 181 ); 182 workbox.routing.registerRoute( 183 new RegExp('.*\\/auth\/.*'), 184 new workbox.strategies.NetworkOnly() 185 ); 186 workbox.routing.registerRoute( 187 new RegExp('.*\\/public\/.*'), 188 new workbox.strategies.NetworkOnly() 189 ); 190 191 // Queue-it: CDN scripts must always be fetched from network. 192 // Stale cached versions would prevent Queue-it config changes from applying. 193 workbox.routing.registerRoute( 194 new RegExp('static\\.queue-it\\.net'), 195 new workbox.strategies.NetworkOnly() 196 ); 197 // Queue-it: /apply must not be served from cache. 198 // Queue-it JS must intercept before a cached page is shown. 199 workbox.routing.registerRoute( 200 new RegExp('.*\\/apply.*'), 201 new workbox.strategies.NetworkOnly() 202 ); 203 204 // Person photos: Prioritise cache, but update in the background. 205 206 const bgSyncPlugin = new workbox.backgroundSync.Plugin( swCaches.dynamic, { 207 maxRetentionTime: 24 * 60 // Retry for max of 24 Hours 208 }); 209 210 // Everything else: Wait 30 seconds to fall back on the cache 211 const pageHandler = workbox.strategies.networkFirst({ 212 cacheName: swCaches.dynamic, 213 networkTimeoutSeconds: 30, 214 plugins: [ 215 new workbox.expiration.Plugin({ 216 // Cache for a maximum of 7 days 217 maxAgeSeconds: 7 * 24 * 60 * 60 218 }), 219 bgSyncPlugin 220 ] 221 }) ; 222 223 // The handle method returns a promise - we can check the response 224 // and serve back the offline.html page. This is Google's recommended 225 // way of achieving custom offline/404 pages via workbox 226 // The Reg Exp matches on any http[s]://xxx/yyy URL. Root URL is not cached. 227 workbox.routing.registerRoute( 228 new RegExp('^(http|https)\\:\\/\\/.*$'), args => { // change from '\/.*' 229 return pageHandler.handle( args ) 230 .then( response => { 231 if( !response ) { 232 return caches.match( swOffline ); 233 } // else if ( response.status === 404 ) { 234 // return caches.match( sw404 ) ; 235 //} 236 return response ; 237 }); 238 } 239 ); 240}
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.