-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice-worker.js
More file actions
47 lines (44 loc) · 1.22 KB
/
service-worker.js
File metadata and controls
47 lines (44 loc) · 1.22 KB
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
let version = 25;
let cachePrincipal = "neander-v"+version
let cacheWhitelist = [cachePrincipal]
let arquivosCache = [
'./',
'css/bootstrap.min.css',
'css/neander.css',
'js/bootstrap.min.js',
'js/jquery-3.2.1.min.js',
'js/neander-js.js',
'js/database.js',
'manifest.json',
'favicon-32x32.png',
'favicon-16x16.png'
];
this.addEventListener('install', function (event) {
event.waitUntil(
caches.open(cachePrincipal).then(function (cache) {
//crio o cache com as versões mais atuais
return Promise.all([
cache.addAll(arquivosCache),
self.skipWaiting()
]);
})
);
})
this.addEventListener('activate', function (event) {
event.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (cacheWhitelist.indexOf(key) === -1) {
return caches.delete(key);
}
}));
})
);
});
this.addEventListener('fetch', function (event) {
// console.log(event.request)
event.respondWith(caches.match(event.request)
.then((resp) => {
return resp || fetch(event.request);
}))
})