-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
1 lines (1 loc) · 923 Bytes
/
Copy pathsw.js
File metadata and controls
1 lines (1 loc) · 923 Bytes
1
const CACHE_NAME="traceflow-v2",ASSETS_TO_CACHE=["./","./index.html","./css/style.css","./js/script.js","./data/ride.gpx","./assets/bike.png","./favicon.ico",];self.addEventListener("install",e=>{self.skipWaiting(),e.waitUntil(caches.open(CACHE_NAME).then(e=>(console.log("TraceFlow: Pre-caching app shell"),e.addAll(ASSETS_TO_CACHE))))}),self.addEventListener("activate",e=>{e.waitUntil(caches.keys().then(e=>Promise.all(e.map(e=>{if(e!==CACHE_NAME)return console.log("TraceFlow: Clearing old cache",e),caches.delete(e)}))).then(()=>self.clients.claim()))}),self.addEventListener("fetch",e=>{if("GET"!==e.request.method)return;let t=new URL(e.request.url).origin===self.location.origin;t?e.respondWith(fetch(e.request).then(t=>{if(t.ok){let n=t.clone();caches.open(CACHE_NAME).then(t=>t.put(e.request,n))}return t}).catch(()=>caches.match(e.request))):e.respondWith(caches.match(e.request).then(t=>t||fetch(e.request)))});