Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Make the SW more resilient to caches being manually cleared. (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffposnick authored and addyosmani committed Sep 20, 2016
1 parent 22d01c6 commit 65852ec
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion service-worker.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ self.addEventListener('fetch', function(event) {
if (shouldRespond) {
event.respondWith(
caches.open(cacheName).then(function(cache) {
return cache.match(urlsToCacheKeys.get(url));
return cache.match(urlsToCacheKeys.get(url)).then(function(response) {
if (response) {
return response;
}
throw Error('The cached response that was expected is missing.');
});
}).catch(function(e) {
// Fall back to just fetch()ing the request if some unexpected error
// prevented the cached response from being valid.
Expand Down

0 comments on commit 65852ec

Please sign in to comment.