-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
52 lines (48 loc) · 1.35 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
const CACHE_NAME = "v1_cache_contador_app_vue"
const urlsToCache = [
"./",
"./img/favicon.png",
"./img/icon32.png",
"./img/icon64.png",
"./img/icon128.png",
"./img/icon256.png",
"./img/icon512.png",
"./img/icon1024.png",
"https://unpkg.com/vue@next",
"./js/main.js",
"./js/mountApp.js",
"./css/style.css",
"https://necolas.github.io/normalize.css/8.0.1/normalize.css"
];
self.addEventListener("install", e => {
e.waitUntil(
caches.open(CACHE_NAME).then(
cache => cache.addAll(urlsToCache).then(
() => self.skipWaiting()
).catch(err => console.log(err))
)
)
});
self.addEventListener("activate", e => {
const cacheWhiteList = [CACHE_NAME]
e.waitUntil(
caches.keys().then(cacheNames =>
Promise.all(cacheNames.map(cacheName => {
if (cacheWhiteList.indexOf(cacheName) == -11) {
return caches.delete(CACHE_NAME)
} else {
}
}))
).then(() => self.clients.claim() )
)
});
self.addEventListener("fetch", e => {
e.respondWith(
caches.match(e.request).then(res => {
if (res) {
return res;
}
return fetch(e.request);
})
)
})