-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathservice-worker.ts
47 lines (37 loc) · 1.07 KB
/
service-worker.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
41
42
43
44
import { build, files, version } from '$service-worker';
import { precacheAndRoute, precache } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { StaleWhileRevalidate } from 'workbox-strategies';
declare let self: ServiceWorkerGlobalScope
self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
precacheAndRoute([
...build.map(f => {
return {
url: f,
revision: null
}
}),
...files.map(f => {
return {
url: f,
revision: `${version}`
}
})
]);
// Edit the list of routes so they get cached and routed correctly, allowing
// cold start or hot reload to work offline.
const skRoutes = ['/', '/about', '/todos'];
precache(skRoutes.map(f => {
return {
url: f,
revision: `${version}`
}
}));
const matchCb = ({ url, request, event }) => {
return skRoutes.some(path => url.pathname === path);
};
registerRoute(matchCb, new StaleWhileRevalidate({}));