logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe
commit: 011eda089abad18c89324ca4bcb6930bb682a0b9
parent: 8dd77f1720476525eef75dce2924fde20eac7bbd
Author: Morgan Bazalgette <the@howl.moe>
Date:   Mon,  2 Apr 2018 18:25:08 +0200

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

Diffstat:

Mapp/javascript/mastodon/service_worker/entry.js10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js @@ -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);