Skip to content

Commit

Permalink
feat: pwa恢复完整缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
ZvonimirSun committed Nov 15, 2024
1 parent 3428f96 commit aaf87d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 38 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"version": "2.0.2",
"private": true,
"packageManager": "pnpm@9.13.2+sha512.88c9c3864450350e65a33587ab801acf946d7c814ed1134da4a924f6df5a2120fd36b46aab68f7cd1d413149112d53c7db3a4136624cfd00ff1846a0c6cef48a",
"license": "GPL-3.0",
"scripts": {
"build": "vue-tsc --noEmit && vite build",
Expand Down
46 changes: 8 additions & 38 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default defineConfig({
overrideManifestIcons: true,
},
workbox: {
globPatterns: ['**/*.html'],
globPatterns: ['**/*'],
cleanupOutdatedCaches: true,
navigateFallback: 'index.html',
runtimeCaching: [
Expand All @@ -128,7 +128,7 @@ export default defineConfig({
},
// cdn
{
urlPattern: ({ url }) => url.hostname.endsWith('cdn.iszy.xyz'),
urlPattern: /^https:\/\/.*cdn\.iszy\.xyz/,
handler: 'CacheFirst',
options: {
cacheName: `${config.key}-cdn`,
Expand All @@ -137,52 +137,22 @@ export default defineConfig({
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [200],
statuses: [0, 200],
},
},
},
// 项目文件动态缓存
// cdn
{
urlPattern: /\.(?:png|jpg|jpeg|svg|ico)$/,
urlPattern: /^https:\/\/.*cdn\.iszy\.cc/,
handler: 'CacheFirst',
options: {
cacheName: `${config.key}-images`,
cacheName: `${config.key}cc-cdn`,
expiration: {
// 最多30个图
maxEntries: 30,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [200],
},
},
},
{
urlPattern: /\.(?:woff|eot|otf|ttf|TTF)$/,
handler: 'CacheFirst',
options: {
cacheName: `${config.key}-font`,
cacheableResponse: {
statuses: [200],
},
},
},
{
urlPattern: /.*\.css.*/,
handler: 'CacheFirst',
options: {
cacheName: `${config.key}-css`,
cacheableResponse: {
statuses: [200],
},
},
},
{
urlPattern: /.*\.js.*/,
handler: 'CacheFirst',
options: {
cacheName: `${config.key}-js`,
cacheableResponse: {
statuses: [200],
statuses: [0, 200],
},
},
},
Expand Down

0 comments on commit aaf87d3

Please sign in to comment.