Skip to content

Commit

Permalink
Deploying to gh-pages from @ e53a2d4 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadalm committed Jan 6, 2024
1 parent 9d18288 commit 2b687a6
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="7622de62937d282a1a3efb963013a939c9e5b87b">
<meta name="app-version" content="e53a2d422d87a5b6b046ba818f7c604fd23aefcd">
<meta name="description" content="Backgammon app that works offline.">
<title>Backgammon</title>
<link rel="stylesheet" href="css/styles.db66a53c8904774df80ed2dacb765b8191c11396.css">
Expand Down
2 changes: 1 addition & 1 deletion js/app.57C0EE03D68039FF5C3BFCDD552374FC.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 = "e53a2d422d87a5b6b046ba818f7c604fd23aefcd";
const urlsToCache = ["","index.html","manifest.json","img/icon.svg","js/app.57C0EE03D68039FF5C3BFCDD552374FC.js","css/styles.db66a53c8904774df80ed2dacb765b8191c11396.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 2b687a6

Please sign in to comment.