This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
swordsnstuff/ServiceWorker.js
T

34 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-09-03 20:56:03 +02:00
const cacheName = "denizk0461-Swords _ Stuff-0.0.3";
2023-08-26 19:48:11 +02:00
const contentToCache = [
2023-09-03 20:56:03 +02:00
"Build/0.0.3.loader.js",
"Build/0.0.3.framework.js",
"Build/0.0.3.data",
"Build/0.0.3.wasm",
2023-08-26 19:48:11 +02:00
"TemplateData/style.css"
];
self.addEventListener('install', function (e) {
console.log('[Service Worker] Install');
e.waitUntil((async function () {
const cache = await caches.open(cacheName);
console.log('[Service Worker] Caching all: app shell and content');
await cache.addAll(contentToCache);
})());
});
self.addEventListener('fetch', function (e) {
e.respondWith((async function () {
let response = await caches.match(e.request);
console.log(`[Service Worker] Fetching resource: ${e.request.url}`);
if (response) { return response; }
response = await fetch(e.request);
const cache = await caches.open(cacheName);
console.log(`[Service Worker] Caching new resource: ${e.request.url}`);
cache.put(e.request, response.clone());
return response;
})());
});