-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceWorker.js
33 lines (28 loc) · 1.07 KB
/
ServiceWorker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const cacheName = "Moti-kitsune-CGA-20240714-0.1.2";
const contentToCache = [
"Build/Build-lite.loader.js",
"Build/Build-lite.framework.js.unityweb",
"Build/Build-lite.data.unityweb",
"Build/Build-lite.wasm.unityweb",
"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;
})());
});