-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathserviceworker.js
43 lines (41 loc) · 1.13 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
var CACHE_NAME = 'aos-servicecache-' + location.host + '-v1';
var urlsToCache = [
'servicecache.txt'
];
self.addEventListener('install', function(event){
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache){
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', function(event){
if(event.request.url.indexOf(".js") > -1 || event.request.url.indexOf(".css") > -1){
event.respondWith(
fetch(event.request).then((netResponse) => {
return netResponse;
})
);
}
if(event.request.url.indexOf('ms_shadows/s') > -1){
event.respondWith(
caches.open(CACHE_NAME).then((cache) => {
return caches.match(event.request).then(
(response) => {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request).then((netResponse) => {
cache.put(event.request, netResponse.clone());
return netResponse;
});
}
);
})
);
}
});