/
workbox-config.js
62 lines (62 loc) 路 1.46 KB
/
workbox-config.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
51
52
53
54
55
56
57
58
59
60
61
62
module.exports = {
globDirectory: 'public/',
globPatterns: [],
offlineGoogleAnalytics: false,
runtimeCaching: [
{
urlPattern: '/',
// use NetworkFirst or NetworkOnly if you redirect un-authenticated user to login page
handler: 'NetworkFirst',
options: {
cacheName: 'start-url',
expiration: {
maxEntries: 1,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
},
},
{
urlPattern: /.*\/(analytics|beacon.min)\.js$/,
handler: 'NetworkOnly',
},
{
urlPattern: /api\/*$/i,
handler: 'NetworkOnly',
},
{
urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'static-fonts',
expiration: {
maxEntries: 4,
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
},
},
},
{
urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp|js)$/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'static-assets',
expiration: {
maxEntries: 64,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
},
},
{
urlPattern: /.*/i,
handler: 'NetworkFirst',
options: {
cacheName: 'others',
expiration: {
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
networkTimeoutSeconds: 10,
},
},
],
swDest: 'public/sw.js',
}