-
Notifications
You must be signed in to change notification settings - Fork 1
/
service-worker.min.js
1 lines (1 loc) · 1.67 KB
/
service-worker.min.js
1
async function onInstall(){console.info("Service worker: Install");const assetsRequests=self.assetsManifest.assets.filter(asset=>offlineAssetsInclude.some(pattern=>pattern.test(asset.url))).filter(asset=>!offlineAssetsExclude.some(pattern=>pattern.test(asset.url))).map(asset=>new Request(asset.url,{integrity:asset.hash,cache:"no-cache"}));await caches.open(cacheName).then(cache=>cache.addAll(assetsRequests)).then(()=>self.skipWaiting())}async function onActivate(){console.info("Service worker: Activate");const cacheKeys=await caches.keys();await Promise.all(cacheKeys.filter(key=>key.startsWith(cacheNamePrefix)&&key!==cacheName).map(key=>caches.delete(key)))}async function onFetch(event){let cachedResponse=null;if(event.request.method==="GET"){const shouldServeIndexHtml=event.request.mode==="navigate",request=shouldServeIndexHtml?"index.html":event.request,cache=await caches.open(cacheName);cachedResponse=await cache.match(request)}return cachedResponse||fetch(event.request)}self.importScripts("./service-worker-assets.js");self.addEventListener("install",event=>{event.waitUntil(Promise.all([onInstall(),self.skipWaiting()]))});self.addEventListener("activate",event=>{event.waitUntil(Promise.all([onActivate(),self.clients.claim(),self.skipWaiting()]).catch(()=>{event.skipWaiting()}))});self.addEventListener("fetch",event=>event.respondWith(onFetch(event)));const cacheNamePrefix="offline-cache-",cacheName=`${cacheNamePrefix}${self.assetsManifest.version}`,offlineAssetsInclude=[/\.dll$/,/\.pdb$/,/\.wasm/,/\.html/,/\.js$/,/\.json$/,/\.css$/,/\.woff$/,/\.png$/,/\.jpe?g$/,/\.gif$/,/\.ico$/,/\.blat$/,/\.dat$/],offlineAssetsExclude=[/^service-worker\.js$/];/* Manifest version: Z9GnTsan */