Created
March 12, 2018 00:44
-
-
Save ritikrishu/21106f971539d50ee9b4bae4017d39d1 to your computer and use it in GitHub Desktop.
Generic fallback depending on server response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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