-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
68 lines (48 loc) · 1.62 KB
/
service-worker.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
const CACHE_NAME = 'my-app-static-files-v1';
const CACHE_DATA_NAME = 'my-app-data-v1';
var urlsToCache = [
'/',
'/app.js'
];
self.addEventListener('install', function(event){
console.log('service worker installing', event);
return event.waitUntil(
self.caches.open(CACHE_NAME)
.then(function(cache){
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('activate', function(event){
console.log('activatinf',event);
var cacheWhiteList = [CACHE_NAME,CACHE_DATA_NAME];
return event.waitUntil(
self.caches.keys()
.then(function(cacheNames){
return Promise.all(
cacheNames.map(function(cacheName){
if(cacheWhiteList.indexOf(cacheName) === -1){
return self.caches.delete(cacheName);
}
})
)
})
);
});
self.addEventListener('fetch', function(event){
console.log("Fetch",event);
// if(event.request.url === 'https://loremflickr.com/cache/resized/968_41745033742_6f72e73a7d_z_320_240_nofilter.jpg'){
// event.respondWith(
// self.fetch('https://loremflickr.com/cache/resized/909_27976427218_c6df6d7b55_320_240_g.jpg', {mode: 'no-cors'})
// )
// }
var dataUrl = "https://api.github.com";
if(event.request.url.indexOf(dataUrl) === -1){
event.repondWith(
self.caches.match(event.request)
.then(function(response){
})
)
}else {
}
});