-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
45 lines (39 loc) · 1.14 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
console.log('Hello from service-worker.js');
importScripts('/public/js/workbox-sw.js');
workbox.routing.registerRoute(
/\.html$/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'html-cache',
}),
);
workbox.routing.registerRoute(
/\.(css|js)$/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'asset-cache',
}),
);
workbox.routing.registerRoute(
/\.(jpg|jpeg|svg|png|gif|ttf|mp3)$/,
// Use the cache if it's available.
new workbox.strategies.CacheFirst({
// Use a custom cache name.
cacheName: 'static-cache',
plugins: [
new workbox.expiration.ExpirationPlugin({
maxEntries: 100,
// Cache for a maximum of a week.
maxAgeSeconds: 7 * 24 * 60 * 60,
}),
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [0, 200],
})
]
})
);
workbox.precaching.precacheAndRoute([
{ url: '/index.html', revision: '2003' },
{ url: '/about.html', revision: '2003' },
{ url: '/links.html', revision: '2004' },
{ url: '/public/css/styles.css', revision: '2003' },
]);
workbox.routing.setDefaultHandler(new workbox.strategies.NetworkFirst());