-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
50 lines (44 loc) · 1.17 KB
/
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
42
43
44
45
46
47
48
49
50
importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js');
const { googleAnalytics } = workbox;
const { ExpirationPlugin } = workbox.expiration;
const { registerRoute } = workbox.routing;
const { CacheFirst, StaleWhileRevalidate } = workbox.strategies;
registerRoute(
({ request }) => request.destination === 'image',
new StaleWhileRevalidate({ cacheName: 'images' }),
);
registerRoute(
({ request }) => request.destination === 'style',
new StaleWhileRevalidate({
cacheName: 'styles',
plugins: [
new ExpirationPlugin({
maxAgeSeconds: 60 * 60 * 24 * 30, // 14 Days
}),
],
}),
);
registerRoute(
({ request }) => request.destination === 'script',
new StaleWhileRevalidate({
cacheName: 'scripts',
plugins: [
new ExpirationPlugin({
maxAgeSeconds: 60 * 60 * 24 * 30, // 14 Days
}),
],
}),
);
registerRoute(
({ request }) => request.destination === 'font',
new CacheFirst({
cacheName: 'fonts',
plugins: [
new ExpirationPlugin({
maxAgeSeconds: 60 * 60 * 24 * 365, // 365 Days
}),
],
}),
);
// Offline Google Analytics
googleAnalytics.initialize();