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

Make the SW more resilient to caches being manually cleared. #186

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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