Skip to content

Commit

Permalink
Service Worker: skip waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Newbytee committed Nov 8, 2020
1 parent 6c4dd81 commit a6a4765
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const URLS_TO_CACHE = [
"https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.js"
];

let refreshing = false;

self.addEventListener("install", function(evnt) {
skipWaiting();

evnt.waitUntil(
caches.open(APP_CACHE)
.then(function(cache) {
Expand Down Expand Up @@ -91,6 +95,16 @@ self.addEventListener("fetch", function(evnt){
);
});

self.addEventListener("controllerchange", () => {
if (refreshing) {
return; // Prevent infinite refresh loops
}

refreshing = true;

window.location.reload();
});

async function refreshCacheEntry(request, clientID) {
fetch(request)
.then(async response => {
Expand Down

0 comments on commit a6a4765

Please sign in to comment.