-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhexo-offline.config.cjs
91 lines (87 loc) · 3.69 KB
/
hexo-offline.config.cjs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// offline config passed to workbox-build.
module.exports = {
globPatterns: ['**/*.{css,eot,gif,html,ijmap,js,png,svg,ttf,woff,woff2,xml}'],
// ^ok ^ok ^ok ^ok ^ok ^ok ^ok ^ok^ok ^ok ^ok ^ok ^ok ^ok ^ok
// 使用 `find . -type f -name '*.*' | sed 's|.*\.||' | sort | uniq | paste -sd '|'` 捕获
// 静态文件合集,如果你的站点使用了例如 webp 格式的文件,请将文件类型添加进去。
globDirectory: 'public',
swDest: 'public/service-worker.js',
maximumFileSizeToCacheInBytes: 10485760, // 缓存的最大文件大小,以字节为单位。
skipWaiting: true,
clientsClaim: true,
runtimeCaching: [ // 如果你需要加载 CDN 资源,请配置该选项,如果没有,可以不配置。
// CDNs - should be CacheFirst, since they should be used specific versions so should not change
// {
// urlPattern: /^https:\/\/mirror\.blog\.stevezmt\.top\/.*/, // 可替换成你的 URL
// handler: 'StaleWhileRevalidate'
// }
{
urlPattern: /.*\.html$/,
/**
* 按需修改使用策略
* StaleWhileRevalidate: 使用缓存的内容尽快响应请求(如果可用),如果未缓存,则回退到网络请求。然后,网络请求用于更新缓存。
* CacheFirst: 缓存优先策略,优先获取缓存中的资源,如果缓存中没有相关资源,那么就发起网络请求。
* NetworkFirst: 尝试从网络获取最新请求,如果请求成功,将响应放入缓存中。如果网络无法返回响应,则将使用缓存响应。
* NetworkOnly: 只使用网络请求获取的资源
* CacheOnly: 只使用缓存中的资源
*/
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'html-cache',
cacheableResponse: { statuses: [0, 200] },
expiration: { maxAgeSeconds: 86400 * 1 } // 1d
}
},
{
urlPattern: /\/$/, // 匹配所有以 / 结尾的 URL
handler: 'StaleWhileRevalidate', // 使用 StaleWhileRevalidate 策略
options: {
cacheName: 'slash-cache', // 缓存名称
cacheableResponse: { statuses: [0, 200] }, // 可缓存的响应状态码
expiration: { maxAgeSeconds: 86400 * 1 } // 缓存有效期为1天
}
},
{
urlPattern: /.*\.(css|js)$/,
handler: 'CacheFirst',
options: {
cacheName: 'css-js-cache',
cacheableResponse: { statuses: [0, 200] },
expiration: { maxAgeSeconds: 86400 * 7 } // 7d
}
},
{
urlPattern: /^(?!.*(sitemap|atom)\.xml$).*\.xml$/,
handler: 'CacheFirst',
options: {
cacheName: 'xml-cache',
cacheableResponse: { statuses: [0, 200] },
expiration: { maxAgeSeconds: 86400 * 7 }, // 7d
}
},
{
urlPattern: /.*\.(png|gif|webp|ico|svg|cur|woff|ijmap|ttf|eot|woff2?)$/,
handler: 'CacheFirst',
options: {
cacheName: 'media-cache',
cacheableResponse: { statuses: [0, 200] }
}
},
{
urlPattern: /.*\/(avatar|banner|favicon|grey|loading|material-\d+)\.(png|gif)$/,
handler: 'CacheFirst',
options: {
cacheName: 'media-preset-cache',
cacheableResponse: { statuses: [0, 200] }
}
},
{
urlPattern: /^https:\/\/(cdn\.staticfile\.org|unpkg\.com|cdn\.bootcdn\.net|cdnjs\.cloudflare\.com|cdn\.jsdelivr\.net|cdn-city\.livere\.com)\/.*/,
handler: 'CacheFirst',
options: {
cacheName: 'cdn-cache',
cacheableResponse: { statuses: [0, 200] }
}
}
]
}