Skip to content

Commit

Permalink
add an autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-42 committed Sep 20, 2023
1 parent 19f7d80 commit c2f8df4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions service-worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// service-worker.js

const CACHE_NAME = 'matrix-game-cache-v4';
const CACHE_VERSION = 'v5'; //todo UPDATE?
const CACHE_NAME = `matrix-game-cache-${CACHE_VERSION}`;
const urlsToCache = [
'/',
'index.html',
Expand Down Expand Up @@ -29,9 +30,28 @@ self.addEventListener('install', event => {
);
});

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== CACHE_NAME) {
return caches.delete(cache);
}
})
);
})
);
});

self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => response || fetch(event.request))
.then(response => {
if (response) {
return response;
}
return fetch(event.request);
})
);
});

0 comments on commit c2f8df4

Please sign in to comment.