-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsw.js
More file actions
58 lines (56 loc) · 1.97 KB
/
sw.js
File metadata and controls
58 lines (56 loc) · 1.97 KB
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
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open('v1').then(function (cache) {
return cache.addAll([
'/',
'/index.html',
'/sw.js',
'/js/eventemitter.js',
'/js/hud.js',
'/js/intro.js',
'/js/links.js',
'/js/main.js',
'/js/swinstall.js',
'/js/three.js',
'/js/tracking.js',
'/js/webcam.js',
'/res/background-tile.svg',
'/res/BF7B0B20FB7A6EC2.png',
'/res/finger_thumb_down.svg',
'/res/finger_thumb_up.svg',
'/res/FINGRR.svg',
'/sounds/background.mp3',
'/sounds/crash.wav',
'/sounds/explosion.wav',
'/sounds/gameover.wav',
'/sounds/lifelost.wav',
'/sounds/pew.wav',
'/styles/calibration.css',
'/styles/index.css',
'/styles/keyframes.css',
'/styles/rules.css',
'/styles/title.css'
]);
})
);
});
self.addEventListener('fetch', function (event) {
event.respondWith(caches.match(event.request).then(function (response) {
// caches.match() always resolves
// but in case of success response will have value
if (response !== undefined) {
return response;
} else {
return fetch(event.request).then(function (response) {
// response may be used only once
// we need to save clone to put one copy in cache
// and serve second one
let responseClone = response.clone();
caches.open('v1').then(function (cache) {
cache.put(event.request, responseClone);
});
return response;
});
}
}));
});