-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
39 lines (32 loc) · 909 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
29
30
31
32
33
34
35
36
37
38
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.2.0/workbox-sw.js');
if (workbox) {
console.log(`Yay! Workbox is loaded 🎉`);
}
else {
console.log(`Boo! Workbox didn't load 😬`);
}
workbox.precaching.precacheAndRoute([
'https://lib.baomitu.com/material-design-icons/3.0.1/iconfont/MaterialIcons-Regular.woff2'
]);
workbox.routing.registerRoute(
/.*\.js$/,
new workbox.strategies.NetworkFirst(),
);
workbox.routing.registerRoute(
/.*\.css$/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'css-cache',
}),
);
workbox.routing.registerRoute(
/\.(?:png|jpg|jpeg|svg|gif)$/,
new workbox.strategies.CacheFirst({
cacheName: 'image-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 30,
maxAgeSeconds: 3600 * 24 * 7,
}),
],
}),
);