Skip to content

Instantly share code, notes, and snippets.

@ritikrishu
Created March 12, 2018 00:44
Show Gist options
  • Save ritikrishu/21106f971539d50ee9b4bae4017d39d1 to your computer and use it in GitHub Desktop.
Save ritikrishu/21106f971539d50ee9b4bae4017d39d1 to your computer and use it in GitHub Desktop.
Generic fallback depending on server response
self.addEventListener('fetch', function(event) {
event.respondWith(
fetch(event.request).then(function(response) {
if (response.status === 404) {
return caches.match('routes/404.html');
}
else if(response.status === 404){
return caches.match('routes/no-mans-land.html')
}
return response
});
}).catch(function() {
//network request failed, device is offline
return caches.match('routes/offline.html');
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment