Commit 011eda08 authored by Morgan Bazalgette's avatar Morgan Bazalgette

Properly cache requests using service workers

fix service workers causing problems

remove uninstalling of service workers

add redirect: follow

Handle response.redirected correctly

instead of returning response, fulfill the original request
parent 8dd77f17
......@@ -24,10 +24,19 @@ self.addEventListener('fetch', function(event) {
const url = new URL(event.request.url);
if (url.pathname.startsWith('/web')) {
// we always make /web/login go through
if (url.pathname.startsWith('/web/login')) {
return;
}
const asyncResponse = fetchRoot();
const asyncCache = openWebCache();
event.respondWith(asyncResponse.then(async response => {
// response was redirected - let's actually do the request from the event
// and return its response
if (response.redirected || response.type === 'opaqueredirect') {
return await fetch(event.request);
}
if (response.ok) {
const cache = await asyncCache;
await cache.put('/web', response);
......@@ -48,6 +57,7 @@ self.addEventListener('fetch', function(event) {
return response;
}));
} else if (process.env.CDN_HOST ? url.host === process.env.CDN_HOST : url.pathname.startsWith('/system/')) {
event.respondWith(openSystemCache().then(async cache => {
const cached = await cache.match(event.request.url);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment