I use workbox generateSW method to generate service worker and this is the config I use :
const workbox = require("workbox-build");
workbox.generateSW({
globDirectory: "./",
globIgnores: ["node_modules/**", "**/generator.js", "**/sw.js"],
globPatterns: ["**/*.{css,js}"],
swDest: "./sw.js",
sourcemap: false,
cleanupOutdatedCaches: true,
clientsClaim: true,
runtimeCaching: [
{
urlPattern: /\.(?:html|htm|xml)$/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "runtimecaching name",
expiration: {
maxAgeSeconds: 1,
},
},
},
],
});
I couldn't find an expiration time to delete the old cache in the docs , so How can I cleanup the cache after sometime with workbox-build generateSW ?
maxAgeSeconds
is not meant to auto cleanup old entries after some time. From the documentation:So
maxAgeSeconds
is the option to control time before the cached request is stale, and the old entry removal is triggered by the request.To check and remove old entries after any request, use
maxEntries
option:If you still need to clean after any request and based on time instead of number of entries, you would need to create your own plugin based on
ExpirationPlugin
and better use inject manifest mode.