Optimize PWA state restoration and loading experience

Co-authored-by: jxxghp <jxxghp@163.com>
This commit is contained in:
Cursor Agent
2025-07-06 08:30:12 +00:00
co-authored by jxxghp
parent 8e282fb216
commit c9867bc453
7 changed files with 649 additions and 86 deletions
+10 -2
View File
@@ -60,6 +60,8 @@ export default defineConfig({
revision: null,
},
],
// 启用导航预加载
navigationPreload: true,
runtimeCaching: [
{
urlPattern: /\.(?:js|css|html)$/,
@@ -115,10 +117,16 @@ export default defineConfig({
},
{
urlPattern: ({ request }) => request.destination === 'document',
handler: 'NetworkFirst',
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'pages-cache',
networkTimeoutSeconds: 10,
cacheKeyWillBeUsed: async ({ request }) => {
// 忽略状态参数,提高缓存命中率
const url = new URL(request.url)
url.searchParams.delete('restored')
url.searchParams.delete('t')
return url.toString()
},
},
},
],