service worker attempt

This commit is contained in:
Pagwin 2025-01-09 14:16:40 -05:00
parent 9b6bbae4a9
commit 04ab549ba8
No known key found for this signature in database
GPG key ID: 81137023740CA260

30
static/js/sw.js Normal file
View file

@ -0,0 +1,30 @@
"use strict";
// used so I can prompt updates to the service worker
const version = "09-01-2025";
const cache = new Cache();
self.addEventListener("install", (event) => {
// can't add /static/* due to demos living there
cache.addAll([
"/",
"/index.html",
"/static/css/*",
"/static/js/*",
"/static/images/*",
"/static/video/*"
]);
});
async function handleCache(event) {
const cache_value = await cache.match(event.request);
if (cache_value === undefined) {
return fetch(event.request);
}
return cache_value;
}
self.addEventListener("fetch", async (event) => {
event.respondWith(handleCache(event));
});