question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

workbox-precache caches error responses

See original GitHub issue

Hi

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:

image

Using workbox 6.0.2

My sw.js

const precacheUrls = self.__WB_MANIFEST;
if (precacheUrls) {
  precacheAndRoute(precacheUrls);
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffposnickcommented, Jan 29, 2021

This is now fixed in the v6.1.0 release.

1reaction
jeffposnickcommented, Jan 28, 2021

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 a handler.fetch(), and the handler.cachePut() should be deferred until after the responseSafeToPrecache result is confirmed to be true. In the current implementation, we’re ending up saving entries to the cache and failing the current install, but the next install attempt succeeds (because we don’t attempt to re-cache entries that are already cached unless their revision 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found