StaleWhileRevalidate do not make the second call to update the Service Worker
See original GitHub issueLibrary Affected: workbox-webpack-plugin
Browser & Platform: “all browsers”.
Issue or Feature Request Description: I am using Next Offline library for this site. I set this configuration:
workboxOpts: {
swDest: '../public/service-worker.js',
maximumFileSizeToCacheInBytes: 20000000,
runtimeCaching: [
{
urlPattern: /https:\/\/fonts\.googleapis\.com\/icon[\w\-_\/\.\:\?\=\&\+]*/,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts',
expiration: {
maxEntries: 10,
maxAgeSeconds: 30 * 24 * 60 * 60, // 1 month
},
},
},
{
urlPattern: /^((?!tracker).)*\.(jpeg|png|jpg|ico|svg)\??.*/,
handler: 'CacheFirst',
options: {
cacheName: 'img-cache',
expiration: {
maxEntries: 15,
maxAgeSeconds: 2 * 24 * 60 * 60, // 2 days
},
},
},
{
urlPattern: /https:\/\/embed.widencdn.net\/img\/cityfurniture.*.(jpeg|png|jpg)\?.*/,
handler: 'StaleWhileRevalidate',
},
{
urlPattern: /https:\/\/auth-cityfurniture.dotcmscloud.com\/(dA|contentAsset\/image)[\w\-_\/\.\:\?\=\&\+]*/,
handler: 'StaleWhileRevalidate',
},
{
urlPattern: /^((?!monetate).)*\.(js)$/,
handler: 'StaleWhileRevalidate',
},
],
},
As the js files are configured with the strategy Stale While Revalidate, when I went to the network tab in the Developers tools I was hoping to see two requests for the files cached in the Service Worker (SW), one for the SW request and one for the update of the data on the SW. But I am seeing just one request for the SW JS files. Am I understanding this wrong? It should do another call to revalidate the content of the SW, right?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Keeping things fresh with stale-while-revalidate - web.dev
stale-while-revalidate helps developers balance between immediacy—loading cached content right away—and freshness—ensuring updates to the cached ...
Read more >Is there a way to delay cache revalidation in service worker?
So I tried to implement the stale-while-revalidate strategy: fetch the data once, then if the response for a given request is already in...
Read more >Strategies for service worker caching - Chrome Developers
While the possibilities are practically endless, this guide will stick with the strategies that ship with Workbox, so you can get a sense...
Read more >Stale-while-revalidate Data Fetching with React Hooks: A Guide
Notice we have added another argument called defaultValue to it. The default value of an API call can be different if you use...
Read more >Service worker: Caching and offline mode strategies - Apiumhub
For example, if a product is already out of stock, we should not get a cached response such as { stock: 5 }....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After investigating a bit more, the reason you’re not seeing revalidation revalidation requests for those URLs is that they’re precached, and therefore the runtime caching strategy doesn’t apply to them. You can verify this by looking at the precache manifest in your service worker:
Precached URLs will be updated automatically “in the background” when the manifest information for them changes. They don’t need to be revalidated at runtime,
Thank you so much @jeffposnick! You are totally right! And thank you for the blog post, really interesting 😃