-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserviceWorker.js
70 lines (65 loc) · 1.48 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
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
// Based off of https://github.com/ryandav/template-progressive-web-app
var dataCacheName = 'kord';
var cacheName = 'kord';
var filesToCache = [
'/',
'./img',
'./img/icons',
'./img/icons/128.png',
'./img/icons/144.png',
'./img/icons/152.png',
'./img/icons/192.png',
'./img/icons/256.png',
'./img/gear.png',
'./img/sawWave.png',
'./img/sineWave.png',
'./img/squareWave.png',
'./img/triangleWave.png',
'./img/gear.png',
'./index.html',
'./manifest.json',
'./script.js',
'./serviceWorker.js',
'./styles.css',
'./submono.js',
'./subpoly.js',
];
var log = function(err) {
console.log(err);
};
self.addEventListener('install', function(e) {
// Install service worker
e.waitUntil(
caches.open(cacheName)
.then(function(cache) {
// Cache app shell
return cache.addAll(filesToCache);
})
.catch(log)
);
});
self.addEventListener('activate', function(e) {
// Activate service worker
e.waitUntil(
caches.keys()
.then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (key !== cacheName && key !== dataCacheName) {
// Remove old cache
return caches.delete(key);
}
}));
})
.catch(log)
);
return self.clients.claim();
});
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.match(e.request)
.then(function(response) {
return response || fetch(e.request);
})
.catch(log)
);
});