workbox custom config code example
Example: workbox config
new GenerateSW({
swDest: resolve(process.cwd(), 'build/service-worker.js'),
runtimeCaching: [
{
handler: 'StaleWhileRevalidate',
urlPattern: /\.(?:js|css|html)$/,
options: {
cacheName: 'static-assets-cache',
cacheableResponse: {
statuses: [0, 200]
},
expiration: {
maxEntries: 100,
maxAgeSeconds: 24 * 60 * 60 * 60
}
}
},
{
handler: 'CacheFirst',
urlPattern: /\.(?:jp?g|png|svg|gif|raw|webp)$/,
options: {
cacheName: 'images-assets-cache',
cacheableResponse: {
statuses: [200]
},
expiration: {
maxEntries: 100,
maxAgeSeconds: 24 * 60 * 60 * 180
}
}
},
{
handler: 'CacheFirst',
urlPattern: /\.(?:woff|woff2|eot|ttf|otf)$/,
options: {
cacheName: 'fonts-assets-cache',
cacheableResponse: {
statuses: [200]
},
expiration: {
maxEntries: 100,
maxAgeSeconds: 24 * 60 * 60 * 180
}
}
}
],
clientsClaim: true,
skipWaiting: true,
cleanupOutdatedCaches: true
}),