workbox-precache caches error responses
See original GitHub issueHi
Library Affected: workbox-precache
Browser & Platform: Google Chrome latest
Issue or Feature Request Description:
Workbox precache module caches 404 error response, but it shouldn’t, See screenshot:
Using workbox 6.0.2
My sw.js
const precacheUrls = self.__WB_MANIFEST;
if (precacheUrls) {
precacheAndRoute(precacheUrls);
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Managing fallback responses - Chrome Developers
Whenever a network failure or cache miss occurs, the caching strategies offered by workbox-strategies will reject consistently. This promotes ...
Read more >javascript - workbox Cache processing does not work with ...
I was using workbox5.14 (@nuxtjs/pwa) to precache the 'message' event by passing the URL to PrecacheController when received.
Read more >Workbox Error: PrecacheController.mjs:194 Uncaught (in ...
Hey Team, I'm getting this error in the deployed site only. ... to Production Netlify gives Workbox Error: bad-precaching-response .
Read more >Caching with service worker and Workbox | Node.js Developer
Precaching means saving files to the cache during the service worker installation, it allows serving cached files without network access.
Read more >Cache handling with Service Workers and the Cache API
To pre-cache using Workbox in the simplest way, we just need to ... catch (error) { // if not found in any of...
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
This is now fixed in the v6.1.0 release.
Ah, thank you for sharing all those steps. I believe this is a regression due to some changes in our precaching logic introduced in Workbox v6:
https://github.com/GoogleChrome/workbox/blob/590d1264f57392b1feb538440858f20a52fe6fdf/packages/workbox-precaching/src/PrecacheStrategy.ts#L142-L166
That
const response = await handler.fetchAndCachePut(request)
line should just be ahandler.fetch()
, and thehandler.cachePut()
should be deferred until after theresponseSafeToPrecache
result is confirmed to betrue
. In the current implementation, we’re ending up saving entries to the cache and failing the currentinstall
, but the nextinstall
attempt succeeds (because we don’t attempt to re-cache entries that are already cached unless theirrevision
has changed).I’ll get a fix out for this targeted for the upcoming
6.1.0
release. Thanks for pointing it out!CC: @philipwalton