forked from SamirPaulb/DSAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
557bb0c
commit 3779a64
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This is the "Offline page" service worker | ||
|
||
|
||
!function(){"use strict";try{self["workbox:sw:5.1.2"]&&_()}catch(t){}const t={backgroundSync:"background-sync",broadcastUpdate:"broadcast-update",cacheableResponse:"cacheable-response",core:"core",expiration:"expiration",googleAnalytics:"offline-ga",navigationPreload:"navigation-preload",precaching:"precaching",rangeRequests:"range-requests",routing:"routing",strategies:"strategies",streams:"streams"};self.workbox=new class{constructor(){return this.v={},this.t={debug:"localhost"===self.location.hostname,modulePathPrefix:null,modulePathCb:null},this.s=this.t.debug?"dev":"prod",this.o=!1,new Proxy(this,{get(e,s){if(e[s])return e[s];const o=t[s];return o&&e.loadModule(`workbox-${o}`),e[s]}})}setConfig(t={}){if(this.o)throw new Error("Config must be set before accessing workbox.* modules");Object.assign(this.t,t),this.s=this.t.debug?"dev":"prod"}loadModule(t){const e=this.i(t);try{importScripts(e),this.o=!0}catch(s){throw console.error(`Unable to import module '${t}' from '${e}'.`),s}}i(t){if(this.t.modulePathCb)return this.t.modulePathCb(t,this.t.debug);let e=["https://storage.googleapis.com/workbox-cdn/releases/5.1.2"];const s=`${t}.${this.s}.js`,o=this.t.modulePathPrefix;return o&&(e=o.split("/"),""===e[e.length-1]&&e.splice(e.length-1,1)),e.push(s),e.join("/")}}}(); | ||
//# sourceMappingURL=workbox-sw.js.map | ||
|
||
|
||
const CACHE = "PWA"; | ||
|
||
// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html"; | ||
const offlineFallbackPage = "ToDo-replace-this-name.html"; | ||
|
||
self.addEventListener("message", (event) => { | ||
if (event.data && event.data.type === "SKIP_WAITING") { | ||
self.skipWaiting(); | ||
} | ||
}); | ||
|
||
self.addEventListener('install', async (event) => { | ||
event.waitUntil( | ||
caches.open(CACHE) | ||
.then((cache) => cache.add(offlineFallbackPage)) | ||
); | ||
}); | ||
|
||
if (workbox.navigationPreload.isSupported()) { | ||
workbox.navigationPreload.enable(); | ||
} | ||
|
||
self.addEventListener('fetch', (event) => { | ||
if (event.request.mode === 'navigate') { | ||
event.respondWith((async () => { | ||
try { | ||
const preloadResp = await event.preloadResponse; | ||
|
||
if (preloadResp) { | ||
return preloadResp; | ||
} | ||
|
||
const networkResp = await fetch(event.request); | ||
return networkResp; | ||
} catch (error) { | ||
|
||
const cache = await caches.open(CACHE); | ||
const cachedResp = await cache.match(offlineFallbackPage); | ||
return cachedResp; | ||
} | ||
})()); | ||
} | ||
}); |