Skip to content

Commit

Permalink
Fix change when multiple apps use same domain
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadalm committed Jan 6, 2024
1 parent 36c0bad commit c4e2923
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion resources/private/worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const relatedAppVersion = '1'; // prop:relatedAppVersion
const urlsToCache = ["/", "index.html", "js/app.js", "css/styles.css", "img/icon.svg", "manifest.json"]; // prop:urlsToCache

const cacheKey = `resources.${relatedAppVersion}`;
const cacheKeyPrefix = 'nenadalm.life-counter.';
const cacheKey = `${cacheKeyPrefix}.resources.${relatedAppVersion}`;

function ensureHtmlVersionMatches(cache) {
return cache.match(new Request('index.html'))
Expand All @@ -23,6 +24,7 @@ self.addEventListener('install', event => {
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys()
.then(keys => keys.filter(key => key.startsWith(cacheKeyPrefix)))
.then(keys => keys.filter(key => key !== cacheKey))
.then(oldKeys => Promise.all(oldKeys.map(key => caches.delete(key))))
);
Expand Down

0 comments on commit c4e2923

Please sign in to comment.