-
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) · 1.79 KB
/
Copy pathsw.js
File metadata and controls
1 lines (1 loc) · 1.79 KB
1
const CACHE_NAME="transitflow-v2",BASE_ASSETS=["/","/index.html","/css/style.css","/js/script.js"],DATA_ASSETS=["/data/gtfs_shapes.geojson","/data/route_colors.json","/data/bus_schedules.json","/data/gtfs_stops.geojson",],ICON_ASSETS=["/assets/icons/bus-stop.png","/assets/icons/route_icon_1.png","/assets/icons/route_icon_10.png","/assets/icons/route_icon_11.png","/assets/icons/route_icon_12.png","/assets/icons/route_icon_13.png","/assets/icons/route_icon_17.png","/assets/icons/route_icon_20.png","/assets/icons/route_icon_23b.png","/assets/icons/route_icon_24.png","/assets/icons/route_icon_25.png","/assets/icons/route_icon_29b.png","/assets/icons/route_icon_2b.png","/assets/icons/route_icon_3b.png","/assets/icons/route_icon_4.png","/assets/icons/route_icon_5b.png","/assets/icons/route_icon_6.png","/assets/icons/route_icon_9.png","/assets/icons/route_icon_e1r.png","/assets/icons/route_icon_e1t.png","/assets/icons/route_icon_t100.png","/assets/icons/route_icon_t101.png","/assets/icons/route_icon_t102.png",],ASSETS_TO_CACHE=[...BASE_ASSETS,...DATA_ASSETS,...ICON_ASSETS];self.addEventListener("install",s=>{self.skipWaiting(),s.waitUntil(caches.open(CACHE_NAME).then(s=>(console.log("TransitFlow: Pre-caching"),s.addAll(ASSETS_TO_CACHE))))}),self.addEventListener("activate",s=>{s.waitUntil(caches.keys().then(s=>Promise.all(s.map(s=>{if(s!==CACHE_NAME)return console.log("TransitFlow: Removing old cache",s),caches.delete(s)}))).then(()=>self.clients.claim()))}),self.addEventListener("fetch",s=>{let n=new URL(s.request.url);n.origin===self.location.origin&&s.respondWith(caches.open(CACHE_NAME).then(t=>t.match(s.request).then(e=>{if(e&&(n.pathname.includes("/assets/")||n.pathname.includes("/data/")))return e;let o=fetch(s.request).then(n=>(200===n.status&&t.put(s.request,n.clone()),n)).catch(()=>e);return e||o})))});