When using the service worker below, the behaviour is inkonsistent accross devices - unfortunately, just one of them is desired so far...
How can I fix my service worker such that the outcome is always like in the first case?
self.addEventListener('fetch', event => {
if(event.request.method !== 'GET')
return;
function versionedURL(request){
switch(request.destination){
case 'image':
case 'script':
case 'style':
let
version = self.serviceWorker.scriptURL.split('?')[1]
;
return new Request(request.url + '?' + version);
default:
return request;
}
}
let
request = event.request.url.startsWith('https://matchflix.ch/') ? versionedURL(event.request) : event.request
;
event.respondWith(caches.open('matchflix')
.then(cache => fetch(request)
.then(response => {
cache.put(request, response.clone());
return response;
})
.catch(() => cache.match(request))
)
);
});
There was a mixup with the www and non-www version. After redirecting everything to the non-www version, it works now properly on every device.