-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceWorker.js
45 lines (42 loc) · 1.57 KB
/
serviceWorker.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
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
workbox.setConfig({debug: false})
const { ExpirationPlugin } = workbox.expiration;
const { registerRoute } = workbox.routing;
const { CacheFirst, NetworkFirst, StaleWhileRevalidate } = workbox.strategies;
const { CacheableResponse, CacheableResponsePlugin } = workbox.cacheableResponse;
const googleAnalytics = workbox.googleAnalytics;
googleAnalytics.initialize();
registerRoute(/\.(?:js|css|woff2)$/, new NetworkFirst({cacheName: 'static-cache'}));
// Need a way to version to detect when NOT to stay statically cached.
registerRoute(new RegExp('https://fonts.googleapis.com/.+'), new StaleWhileRevalidate({cacheName: 'static-cache'}));
registerRoute(new RegExp('https:.*min\.(css|js)'), new CacheFirst({cacheName: 'static-cache'}));
registerRoute(/\.(?:png|jpg|jpeg|svg|gif|ico|webp)$/,
new CacheFirst({
cacheName: 'images-cache',
plugins: [
new ExpirationPlugin({
maxEntries: 30,
maxAgeSeconds: 7 * 24 * 60 * 60,
})
]
})
);
registerRoute(
new RegExp('https://api.box.com/.+'),
new NetworkFirst({
cacheName: 'api-cache',
plugins: [
new CacheableResponsePlugin({
statuses: [200],
}),
new ExpirationPlugin({
maxAgeSeconds: 7 * 24 * 60 * 60,
})
]
})
);
workbox.precaching.precacheAndRoute([
{url: 'index.html', revision: 'v1.0.9'},
{url: 'src/pages/dataRequest.js', revision: 'v1.0.9'},
]
);