-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.ts
40 lines (37 loc) · 819 Bytes
/
sw.ts
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
const cacheName = 'my-site-cache-v1'
const urlsToCache = [
'/',
'/index.html',
'/assets',
// Add more URLs of your assets to cache as needed
]
self.addEventListener('install', event => {
// @ts-expect-error ...
event.waitUntil(
caches.open(cacheName).then(cache => cache.addAll(urlsToCache))
)
})
self.addEventListener('fetch', event => {
// @ts-expect-error ...
event.respondWith(
caches
// @ts-expect-error ...
.match(event.request)
// @ts-expect-error ...
.then(response => response || fetch(event.request))
)
})
self.addEventListener('activate', event => {
// @ts-expect-error ...
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== cacheName) {
return caches.delete(cache)
}
})
)
})
)
})