debug service worker

This commit is contained in:
mgabdev 2020-04-03 19:18:21 -04:00
parent 0a89c7b775
commit c6fdcb91c8

View File

@ -18,13 +18,13 @@ function fetchRoot() {
// Cause a new version of a registered Service Worker to replace an existing one // Cause a new version of a registered Service Worker to replace an existing one
// that is already installed, and replace the currently active worker on open pages. // that is already installed, and replace the currently active worker on open pages.
self.addEventListener('install', function (event) { self.addEventListener('install', function(event) {
event.waitUntil(Promise.all([openWebCache(), fetchRoot()]).then(([cache, root]) => cache.put('/', root))); event.waitUntil(Promise.all([openWebCache(), fetchRoot()]).then(([cache, root]) => cache.put('/', root)));
}); });
self.addEventListener('activate', function (event) { self.addEventListener('activate', function(event) {
event.waitUntil(self.clients.claim()); event.waitUntil(self.clients.claim());
}); });
self.addEventListener('fetch', function (event) { self.addEventListener('fetch', function(event) {
const url = new URL(event.request.url); const url = new URL(event.request.url);
if (url.pathname === '/auth/sign_out') { if (url.pathname === '/auth/sign_out') {
@ -69,16 +69,16 @@ self.addEventListener('fetch', function (event) {
//non-webapp routes //non-webapp routes
} else if (url.pathname.startsWith('/')) { } else if (url.pathname.startsWith('/')) {
// : TODO : if is /web // : TODO : if is /web
const asyncResponse = fetchRoot(); // const asyncResponse = fetchRoot();
const asyncCache = openWebCache(); // const asyncCache = openWebCache();
event.respondWith(asyncResponse.then( // event.respondWith(asyncResponse.then(
response => { // response => {
const clonedResponse = response.clone(); // const clonedResponse = response.clone();
asyncCache.then(cache => cache.put('/', clonedResponse)).catch(); // asyncCache.then(cache => cache.put('/', clonedResponse)).catch();
return response; // return response;
}, // },
() => asyncCache.then(cache => cache.match('/')))); // () => asyncCache.then(cache => cache.match('/'))));
} /* else if (storageFreeable && (ATTACHMENT_HOST ? url.host === ATTACHMENT_HOST : url.pathname.startsWith('/system/'))) { } /* else if (storageFreeable && (ATTACHMENT_HOST ? url.host === ATTACHMENT_HOST : url.pathname.startsWith('/system/'))) {
event.respondWith(openSystemCache().then(cache => { event.respondWith(openSystemCache().then(cache => {
return cache.match(event.request.url).then(cached => { return cache.match(event.request.url).then(cached => {
@ -101,4 +101,4 @@ self.addEventListener('fetch', function (event) {
}); });
})); }));
} */ } */
}); });