-
Notifications
You must be signed in to change notification settings - Fork 3
/
service-worker.js
68 lines (60 loc) · 1.52 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
(function() {
'use strict';
var cacheName = 'cache_v4.2';
var cacheFiles = [
'./',
'./index.html',
'./sw.js',
'./manifest.json',
'./src/assets/js/libs/sweetalert.min.js',
'./src/assets/js/libs/leaflet.awesome-markers.js',
'./src/assets/images/evento.svg',
'./src/assets/images/fixo.svg',
'./src/assets/images/markers-shadow.png',
'./src/assets/images/[email protected]',
'./src/assets/images/markers-soft.png',
'./src/assets/images/[email protected]',
'./dist/bundle.js'
];
// ====
// Primeiro evento / acontece apenas uma vez
function Install(event) {
event.waitUntil(
caches
.open(cacheName)
.then(function(cache) {
return cache.addAll(cacheFiles)
})
.then(function() {
return self.skipWaiting()
})
);
}
// Deleta o cache mais antigo
function Activate(event) {
event.waitUntil(
caches
.keys()
.then(function (keyList) {
return Promise.all(keyList.map(function (key) {
if (key !== cacheName) return caches.delete(key)
}))
})
)
return self.clients.claim();
}
// Trigger para todos os requests da aplicação
function Fetch(event) {
event.respondWith(
caches
.match(event.request)
.then(function(response) {
return response || fetch(event.request)
})
);
}
// ====
self.addEventListener('install', Install);
self.addEventListener('activate', Activate);
self.addEventListener('fetch', Fetch);
})();