-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
28 lines (23 loc) · 881 Bytes
/
service-worker.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
importScripts(
'https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js'
);
workbox.precaching.precacheAndRoute([{"revision":"133cb6ccde559821aa7b1fa541dd43c5","url":"public/offline.html"}]);
const networkFirstHandler = new workbox.strategies.NetworkFirst({
cacheName: 'dynamic',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 50
}),
new workbox.cacheableResponse.Plugin({
statuses: [200]
})
]
});
const FALLBACK_URL = workbox.precaching.getCacheKeyForURL('public/offline.html');
const matcher = ({ event }) => event.request.mode === 'navigate';
const handler = args =>
networkFirstHandler
.handle(args)
.then(response => response || caches.match(FALLBACK_URL))
.catch(() => caches.match(FALLBACK_URL));
workbox.routing.registerRoute(matcher, handler);