-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
43 lines (38 loc) · 1.14 KB
/
sw.js
File metadata and controls
43 lines (38 loc) · 1.14 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
/**
* Service Worker
* @author Luiz Fernando
*/
// Instalação (cache "armazenamento local")
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('static')
.then((cache) => {
cache.add('./flexV2/')
cache.add('./flexV2/index.html')
cache.add('./flexV2/style.css')
cache.add('./flexV2/app.js')
cache.add('./flexV2/imgflex.png')
cache.add('./flexV2/img/calcflex.png')
cache.add('./flexV2/img/etanol.png')
cache.add('./flexV2/img/gasolina.png')
})
)
})
// Ativação
self.addEventListener('activate', (event) => {
console.log("Ativando o service worker...", event)
return self.clients.claim()
})
// Interceptação (solicitações https servindo em cache quando off-line)
self.addEventListener('fetch', (event) => {
event.respondWith (
caches.match(event.request)
.then((response) => {
if (response) {
return response
} else {
return fetch(event.request)
}
})
)
})