-
Notifications
You must be signed in to change notification settings - Fork 6
/
sw.js
46 lines (43 loc) · 1.16 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
const version = '1.1.1';
const cacheName = `filelove-${version}`;
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(
[
'/index.html',
'/assets/css/style.css',
'/assets/js/webtorrent.min.js',
'/assets/js/app.js'
]
);
})
);
});
self.addEventListener('fetch', function(event) {
if (event.request.method !== "POST") {
event.respondWith(
caches.open(cacheName).then(function(cache) {
return fetch(event.request).then(function(response) {
cache.put(event.request, response.clone());
return response;
});
})
);
}
});
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
// Return true if you want to remove this cache,
// but remember that caches are shared across
// the whole origin
}).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});