我开始使用 next-pwa,基本设置就像一个魅力。现在它想使用运行时缓存选项,这对我不起作用:
我的 next.config.js 包括标准缓存条目和一个自定义条目,该条目应该为每个到 /api/todoitem 的请求使用策略 StaleWhileRevalidate:
const withPWA = require("next-pwa");
const defaultRuntimeCaching = require("next-pwa/cache");
module.exports = withPWA({
reactStrictMode: true,
pwa: {
dest: "public",
disable: false, // disable PWA
register: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: /\/api\/todoitem/,
method: "GET",
handler: "StaleWhileRevalidate",
options: {
cacheName: "todoApp-api",
expiration: {
maxEntries: 64,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
},
},
...defaultRuntimeCaching,
],
},
});
重新启动 npm run dev 启动浏览器 -> fetch GET /api/todoitem -> 和 console.log 告诉我
workbox Network request for '/api/todoitem' returned a response with status '200'.
workbox Using NetworkOnly to respond to '/api/todoitem'
我尝试了多种正则表达式组合,包括在我的 runtimeCache 条目之前或之后的 defaultRuntimeCaching 均无济于事。
任何使自定义 runtimeCache 规则正常工作的提示将不胜感激。
下一个.js 12.0.7
下一个 pwa 5.4.4
node.js v14.18.2