-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js.old
42 lines (42 loc) · 1.95 KB
/
sw.js.old
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
const workboxVersion='4.3.1';
importScripts(`https://cdn.jsdelivr.net/npm/[email protected]/workbox/workbox-sw.js`);workbox.setConfig({modulePathPrefix:`https://cdn.jsdelivr.net/npm/[email protected]/workbox/`});
let cacheSuffixVersion = '-190413';
const precacheCacheName = workbox.core.cacheNames.precache,
runtimeCacheName = workbox.core.cacheNames.runtime,
maxEntries = 100;
workbox.core.setCacheNameDetails({
prefix: 'vigorous-pro',
suffix: cacheSuffixVersion
});
workbox.precaching.precacheAndRoute(['https://cdn.jsdelivr.net/npm/[email protected]', 'https://cdn.jsdelivr.net/npm/[email protected]', 'https://cdn.jsdelivr.net/gh/sukkaw/hexo-theme-suka@latest/source/css/style.min.css'], );
workbox.googleAnalytics.initialize();
workbox.routing.registerRoute(/(.*(?:alicdn|360buyimg|joybuy).com)|i.loli.net|i.yecdn.com/, new workbox.strategies.CacheFirst({
cacheName: 'img-cache' + cacheSuffixVersion,
plugins: [new workbox.expiration.Plugin({
maxEntries, maxAgeSeconds: 30 * 24 * 60 * 60,
}), new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}), ]
}));
workbox.routing.registerRoute(new RegExp('^https://cdn.jsdelivr.net'), new workbox.strategies.CacheFirst({
cacheName: 'static-lib' + cacheSuffixVersion,
plugins: [new workbox.expiration.Plugin({
maxAgeSeconds: 30 * 24 * 60 * 60,
}), new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}), ]
}));
workbox.routing.registerRoute(/.*.(?:png|jpg|jpeg|svg|gif)/, new workbox.strategies.StaleWhileRevalidate({
cacheName: 'img-cache' + cacheSuffixVersion,
}));
workbox.routing.registerRoute(/.*.(css|js)/, new workbox.strategies.StaleWhileRevalidate({
cacheName: 'static-assets-cache',
}));
workbox.routing.registerRoute('/sw.js', new workbox.strategies.StaleWhileRevalidate());
workbox.routing.setDefaultHandler(new workbox.strategies.NetworkFirst({
options: [{
networkTimeoutSeconds: 3,
}]
}));
workbox.core.skipWaiting();
workbox.core.clientsClaim();