-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
53 lines (45 loc) · 1.33 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
51
52
53
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
if (workbox) {
workbox.precaching.precacheAndRoute([{"revision":"b6d99193ad6de161f5b877740e9e9bb0","url":"dist/bundle.js"},{"revision":"bd2b8dbcea07acb647dee34fb64204ba","url":"dist/main.css"}]);//End precache
workbox.googleAnalytics.initialize({
parameterOverrides: {
cd1: "Offline"
}
});
//Ignore preview and admin files
workbox.routing.registerRoute(
/wp-admin(.*)|(.*)preview=true(.*)|(.*)\/plugins\/(.*)/,
new workbox.strategies.NetworkOnly()
);
//Stale while revalidate for js and css that are not in precache
workbox.routing.registerRoute(
/\.(?:js|css)$/,
new workbox.strategies.StaleWhileRevalidate()
);
//Limit to 50 images in cache
workbox.routing.registerRoute(
/\.(?:png|jpg|svg|gif|webp)(.*)$/,
new workbox.strategies.CacheFirst({
cacheName: 'images-cache',
cacheExpiration: {
maxEntries: 50
}
})
);
//Cache wp pages
workbox.routing.registerRoute(
new RegExp('/(.*)/'),
new workbox.strategies.NetworkFirst({
cacheName: 'pages-cache',
plugins: [
new workbox.expiration.ExpirationPlugin({
maxEntries: 20,
maxAgeSeconds: 60 * 60 * 24
}),
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [0, 200]
})
]
})
);
}