Frontend: Remove old service worker caches

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-27 13:07:36 +00:00
parent 6297422515
commit 52bbcb4489
2 changed files with 17 additions and 8 deletions

View File

@ -1,7 +1,5 @@
/*Overrides*/
.titleimg{
height: 200px;
width: 234.38px;
padding-bottom: 0px;
}
.small-lookup-box{

View File

@ -1,16 +1,16 @@
/* Service Worker */
/* Service Worker */
const appVersion = "0.0.1-dev"
const cacheName = "owlboard0-0-1-dev"
const cacheName = `owlboard-${appVersion}`
const cacheIDs = [cacheName]
const cacheFiles = [
"/404.html",
"/board.html",
"/conn-err.html",
"/find-code.html",
"/help.html",
"/",
"/issue.html",
"/settings.html",
"/manifest.json",
"/styles/fonts/firamono/firamono-500.woff2",
"/styles/fonts/firamono/firamono-regular.woff2",
"/styles/fonts/urwgothic/urwgothic.woff2",
@ -50,13 +50,24 @@ self.addEventListener("install", (e) => {
e.respondWith(
(async () => {
const r = await caches.match(e.request);
console.log(`[Service Worker] Fetching resource: ${e.request.url}`);
if (r) {
return r;
}
const response = await fetch(e.request);
console.log(`[Service Worker] Fetching from server: ${e.request.url}`);
console.log(`[Service Worker] Not cached - fetching from server: ${e.request.url}`);
return response;
})()
);
});
self.addEventListener('activate', function (event) {
event.waitUntil(caches.keys().then(function (keys) {
return Promise.all(keys.filter(function (key) {
return !cacheIDs.includes(key);
}).map(function (key) {
return caches.delete(key);
}));
}).then(function () {
return self.clients.claim();
}));
});