fix: redirects with the service worker (#183)
This commit is contained in:
parent
e13147ba1e
commit
940bbbea90
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
$version = "v1.11.2";
|
$version = "v1.11.3";
|
||||||
?>
|
?>
|
||||||
@ -99,10 +99,19 @@ self.addEventListener('install', function(event) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
self.addEventListener('fetch', function(event) {
|
self.addEventListener('fetch', function(event) {
|
||||||
event.respondWith(
|
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);
|
return caches.match(event.request);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user