-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
98 lines (84 loc) · 3 KB
/
service-worker.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const cacheName = "cache2"; // Change value to force update
self.addEventListener("install", event => {
// Kick out the old service worker
self.skipWaiting();
event.waitUntil(
caches.open(cacheName).then(cache => {
return cache.addAll([
'/',
'/index.html',
'/vanitas-no-carte-anime.gif',
'/games/index.html',
'/rickroll2222Google.html',
'/games/mario64/sm64.us.f3dex2e.wasm',
'/games/mario64/sm64.us.f3dex2e.js',
'/games/mario64/index.html',
'/games/Paper Minecraft v11.html',
'/200w.gif',
'/games/doodle-jump/doodle.png'
'/games/doodle-jump/index.html'
'/games/doodle-jump/main.js'
'/games/doodle-jump/sprites.png'
'/games/doodle-jump/style.css'
'/Slope-Game/Build/slope_data.unityweb'
'/Slope-Game/Build/slope_framework.unityweb'
'/Slope-Game/Build/slope_memory.unityweb'
'/Slope-Game/Build/slope_wasmcode.unityweb'
'/Slope-Game/Build/slope_wasmframework.unityweb'
'/Slope-Game/Build/slope.json'
'/Slope-Game/TemplateData/progressEmpty.Dark.png'
'/Slope-Game/TemplateData/progressFull.Dark.png'
'/Slope-Game/TemplateData/progressLogo.Dark.png'
'/Slope-Game/TemplateData/style.css'
'/Slope-Game/TemplateData/unityloader41.js'
'/Slope-Game/TemplateData/UnityProgress.js'
'/Slope-Game/index.html'
'/games/baldis-basics/TemplateData/progressEmpty.Dark.png'
'/games/baldis-basics/TemplateData/progressFull.Dark.png'
'/games/baldis-basics/TemplateData/progressLogo.Dark.png'
'/games/baldis-basics/TemplateData/style.css'
'/games/baldis-basics/TemplateData/UnityProgress.js'
'/games/baldis-basics/unity/baldi.data.unityweb'
'/games/baldis-basics/unity/baldi.wasm.code.unityweb'
'/games/baldis-basics/unity/baldi.wasm.framework.unityweb'
'/games/baldis-basics/baldi.js'
'/games/baldis-basics/baldi.json'
'/games/baldis-basics/firebase-app.js'
'/games/baldis-basics/index.html'
'/games/baldis-basics/splash.png'
]
// Add more paths for other static assets you want to cache here
]);
})
);
});
self.addEventListener("activate", event => {
// Delete any non-current cache
event.waitUntil(
caches.keys().then(keys => {
Promise.all(
keys.map(key => {
if (![cacheName].includes(key)) {
return caches.delete(key);
}
})
)
})
);
});
// Offline-first, cache-first strategy
// Kick off two asynchronous requests, one to the cache and one to the network
// If there's a cached version available, use it, but fetch an update for next time.
// Gets data on screen as quickly as possible, then updates once the network has returned the latest data.
self.addEventListener("fetch", event => {
event.respondWith(
caches.open(cacheName).then(cache => {
return cache.match(event.request).then(response => {
return response || fetch(event.request).then(networkResponse => {
cache.put(event.request, networkResponse.clone());
return networkResponse;
});
})
})
);
});