You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
I am using sw-precache for adding offline support to a web app.
My setup:
Static website with CSS/JS/HTML Dynamic content is handled via
custom indexedDB solution.
Grunt task used generate the service-worker.
sw-precache (4.0.0) used to cache ALL the static
assets.
cache headers on service-worker.js set on apache as
follows:
<LocationMatch "service-worker\.js.*">
Header set Cache-Control "max-age=0, no-cache"
</LocationMatch>
Things seem to work fine in usual cases. But if for some reason, the user clears the cache (e.g In chrome dev tools -> Applications -> Clear Storage (Select everything) -> click 'clear selected'), my web pages don't load even If I am online and I see following error in console:
When I look at the generated service-worker.js, I notice the following code.
// If shouldRespond was set to true at any point, then call
// event.respondWith(), using the appropriate cache key.
if (shouldRespond) {
event.respondWith(
caches.open(cacheName).then(function(cache) {
return cache.match(urlsToCacheKeys.get(url));
}).catch(function(e) {
// Fall back to just fetch()ing the request if some unexpected error
// prevented the cached response from being valid.
console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e);
return fetch(event.request);
})
);
When debugging, I don't see the catch block getting executed. Also see the attached debug output of the object returned catch.match that is passed to respondWith()
So my questions:
Why does sw-precache not fallback to network when it does not find the entry in cache?
Is there anyway to force network request when a request entry is not found in cache?
The text was updated successfully, but these errors were encountered:
@jeffposnick Thanks for the opening the issue and for the fix. I do have one question on the fix though. It seems like the fix will fallback to network request in cases where the cache.match() fails return a proper response. Which is good, but it seems it will not update the cache? So if the user goes offline he is still missing that resource?
That's right. If the user explicitly chooses to delete their caches, that's an exceptional condition that sw-precache doesn't attempt to undo by repopulating the caches. Obviously the service worker should continue allowing the requests to go through via the network, though, which was the intended behavior and what that fix accomplishes.
(In practice, I think it's much more likely that a user who clears all their caches will also end up unregistering all service workers, which is what happens by default. Keeping a service worker registration but clearing out caches is an edge case.)
This was originally asked at http://stackoverflow.com/questions/39563666, but it makes more sense in the
sw-precache
issue tracker, not on Stack Overflow.I am using sw-precache for adding offline support to a web app.
My setup:
custom indexedDB solution.
assets.
follows:
Things seem to work fine in usual cases. But if for some reason, the user clears the cache (e.g In chrome dev tools -> Applications -> Clear Storage (Select everything) -> click 'clear selected'), my web pages don't load even If I am online and I see following error in console:
The FetchEvent for "https://my.somedomain.com/somepath/somepage.html" resulted in a network error response: an object that was not a Response was passed to respondWith().
When I look at the generated service-worker.js, I notice the following code.
When debugging, I don't see the catch block getting executed. Also see the attached debug output of the object returned catch.match that is passed to respondWith()
So my questions:
The text was updated successfully, but these errors were encountered: