-
Notifications
You must be signed in to change notification settings - Fork 1
/
sw.js
63 lines (53 loc) · 1.55 KB
/
sw.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
let version = '4.4.2';
let cacheName = "TripmeV" + version;
let filesToCache = [
'/',
'/index.html',
'/index.html?pwa=true',
'/experiences/hydrogen/hydrogen.html',
'/experiences/helium/helium.html',
'/experiences/lithium/lithium.html',
'/experiences/hydrogen/sketch.js',
'/experiences/hydrogen/shape.js',
'/experiences/helium/sketch.js',
'/experiences/lithium/sketch.js',
'/experiences/lithium/brush.js',
'/css/main.css',
'/js/main.js',
'/vendors/p5/p5.sound.min.js',
'/vendors/p5/p5.dom.min.js',
'/vendors/p5/p5.min.js',
]
self.addEventListener("install", function(event) {
console.log(version + ': install event in progress.');
event.waitUntil(
caches.open(cacheName)
.then(function(cache) {
return cache.addAll(filesToCache);
})
.then(function() {
console.log('service worker: install completed');
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
self.addEventListener('activate', function(e) {
console.log('service worker: Activate');
e.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (key !== cacheName) {
console.log('service worker: Removing old cache', key);
return caches.delete(key);
}
}));
})
);
return self.clients.claim();
});