-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
35 lines (32 loc) · 712 Bytes
/
sw.js
File metadata and controls
35 lines (32 loc) · 712 Bytes
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
const CACHE_NAME = "picture_app"
const assets = [
"/",
"/index.html",
"/index.css",
"/index.js",
"/assets/camera.svg",
]
self.addEventListener("install", installEvent => {
installEvent.waitUntil(
caches.open(CACHE_NAME).then(cache => {
cache.addAll(assets)
})
);
});
self.addEventListener('activate', evt => {
evt.waitUntil(
caches.keys().then(keys => {
return Promise.all(keys
.filter(key => key !== CACHE_NAME)
.map(key => caches.delete(key))
);
})
);
});
self.addEventListener("fetch", fetchEvent => {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then(res => {
return res || fetch(fetchEvent.request)
})
)
})