-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserviceworker.js
51 lines (44 loc) · 1.42 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
//https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook
const cacheName = 'serviceCache'
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(
[]
);
})
);
});
// self.addEventListener('activate', function(event) {
// var cacheKeeplist = ['serviceCache'];
// event.waitUntil(
// caches.keys().then((keyList) => {
// return Promise.all(keyList.map((key) => {
// if (cacheKeeplist.indexOf(key) === -1) {
// return caches.delete(key);
// }
// }));
// })
// );
// });
// self.addEventListener('fetch', function(event) {
// if (event.request.method !== 'GET') { return }
// if (
// event.request.url.includes('amazon-adsystem') ||
// event.request.url.includes('browser-sync') ||
// event.request.url.includes('media-amazon') ||
// event.request.url.includes('cloudflare-static') ||
// event.request.url.includes('google-analytics') ) {
// return false;
// }
// event.respondWith(
// caches.open(cacheName).then(function(cache) {
// return cache.match(event.request).then(function (response) {
// return response || fetch(event.request).then(function(response) {
// cache.put(event.request, response.clone());
// return response;
// });
// });
// })
// );
// });