-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
57 lines (53 loc) · 1.39 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
47
48
49
50
51
52
53
54
55
56
57
const CACHEVER = '13033v1.10' ;
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHEVER).then((cache) => {
return cache.addAll([
'index.html',
'manifest.json',
'images/icon-72x72.png',
'images/icon-96x96.png',
'images/icon-128x128.png',
'images/icon-144x144.png',
'images/icon-192x192.png',
'images/icon-512x512.png',
'images/ajax-loader.gif',
'custom.css',
'jqm.css',
'jq.js',
'jqm.js',
'app.js'
]);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(caches.match(event.request).then(function(response) {
if (response !== undefined) {
return response;
} else {
return fetch(event.request).then(function (response) {
let responseClone = response.clone();
caches.open(CACHEVER).then(function (cache) {
cache.put(event.request, responseClone);
});
return response;
}).catch(function () {
return null ;
});
}
}));
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (CACHEVER != cacheName) {
return caches.delete(cacheName);
}
})
);
})
);
});