-
Notifications
You must be signed in to change notification settings - Fork 3
/
sw.js
41 lines (35 loc) · 982 Bytes
/
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
const CACHE = "pwabuilder-offline";
importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js"
);
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
workbox.routing.registerRoute(
({ request }) => request.destination === 'image',
new workbox.strategies.StaleWhileRevalidate({
cacheName: `${CACHE}-images`,
})
);
workbox.routing.registerRoute(
({ request }) => request.destination === 'font',
new workbox.strategies.StaleWhileRevalidate({
cacheName: `${CACHE}-fonts`,
})
);
workbox.routing.registerRoute(
({ request }) =>
request.destination === 'script' && !/scheduleDay/.test(request.url),
new workbox.strategies.StaleWhileRevalidate({
cacheName: `${CACHE}-scripts`,
})
);
workbox.routing.registerRoute(
new RegExp("/*"),
new workbox.strategies.NetworkFirst({
cacheName: CACHE,
networkTimeoutSeconds: 5,
})
);