Skip to content

Commit

Permalink
fix: redirects with the service worker (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite committed Mar 2, 2024
1 parent e13147b commit 940bbbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$version = "v1.11.2";
$version = "v1.11.3";
?>
13 changes: 11 additions & 2 deletions service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
);
Expand Down

0 comments on commit 940bbbe

Please sign in to comment.