-
Notifications
You must be signed in to change notification settings - Fork 1
/
sw.js
41 lines (37 loc) · 836 Bytes
/
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
var _cacheName = 'cimbar-js-v0.6.1';
var _cacheFiles = [
'/',
'/index.html',
'/cimbar_js.js',
// '/cimbar_js.wasm',
'/favicon.ico',
'/main.js',
// '/pwa.json'
];
// fetch files
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(_cacheName).then(function(cache) {
return cache.addAll(_cacheFiles);
})
);
self.skipWaiting();
});
// serve from cache
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.match(e.request).then(function(response) {
return response || fetch(e.request);
})
);
});
// clean old caches
self.addEventListener('activate', function(e) {
e.waitUntil(function() {
caches.keys().then(function(names) {
for (var i in names)
if (names[i] != _cacheName)
caches.delete(names[i]);
});
});
});