fix: redirects with the service worker (#183)

This commit is contained in:
Miguel Ribeiro 2024-03-02 16:07:45 +01:00 committed by GitHub
parent e13147ba1e
commit 940bbbea90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -1,3 +1,3 @@
<?php
$version = "v1.11.2";
$version = "v1.11.3";
?>

View File

@ -99,10 +99,19 @@ self.addEventListener('install', function(event) {
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
fetch(event.request, { redirect: 'follow' }).catch(function() {
fetch(event.request.clone()).then(function(response) {
// Check if the response is a redirect
if (response.redirected) {
// If the response is a redirect, follow it by making a new fetch request
return fetch(response.url);
} else {
// If the response is not a redirect, return it as-is
return response;
}
}).catch(function(error) {
// If fetching fails, try to retrieve the response from cache
return caches.match(event.request);
})
);