Skip to content

Commit

Permalink
Deploying to gh-pages from @ 6fe7310 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadalm committed Jan 6, 2024
1 parent 2d28d6c commit 0bf2b12
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#121212">
<meta name="app-version" content="514a42707469ffcb9f24570c4359f096e47a2065">
<meta name="app-version" content="6fe73104ca4606d7eac7c5de2b8aea1ca1840849">
<meta name="description" content="Simple life counter app that works offline.">
<title>Life counter</title>
<link rel="stylesheet" href="css/styles.9e19bd93a962bf6536dd8278190bfd72978658ef.css">
Expand Down
2 changes: 1 addition & 1 deletion js/app.7C040D89C8D45CD847E83929BE3F9348.js.map

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions worker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
const relatedAppVersion = "6fe73104ca4606d7eac7c5de2b8aea1ca1840849";
const urlsToCache = ["","index.html","manifest.json","img/icon.svg","js/app.7C040D89C8D45CD847E83929BE3F9348.js","css/styles.9e19bd93a962bf6536dd8278190bfd72978658ef.css"];

const cacheKey = `resources.${relatedAppVersion}`;

function ensureHtmlVersionMatches(cache) {
return cache.match(new Request('/index.html'))
.then(response => response.text())
.then(html => html.match(/<meta name="app-version" content="(.*?)">/)[1])
.then(version => {
if (version !== relatedAppVersion) {
return Promise.reject(`Incorrect index.html version ${version} doesn't match worker.js version ${relatedAppVersion}`);
}
})
}

self.addEventListener('install', event => {
event.waitUntil(caches.open('resources').then(cache => cache.addAll(urlsToCache)));
event.waitUntil(caches.open(cacheKey).then(
cache => cache.addAll(urlsToCache)
.then(() => ensureHtmlVersionMatches(cache))));
});

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys()
.then(keys => keys.filter(key => key !== cacheKey))
.then(oldKeys => Promise.all(oldKeys.map(key => caches.delete(key))))
);
});

self.addEventListener('fetch', event => {
event.respondWith(caches.open('resources')
event.respondWith(caches.open(cacheKey)
.then(cache => cache.match(event.request))
.then(response => response ?? fetch(event.request)));
});

0 comments on commit 0bf2b12

Please sign in to comment.