-
-
Save jakearchibald/766e0bffb87c87baeba3 to your computer and use it in GitHub Desktop.
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
var networkDataReceived = false; | |
startSpinner(); | |
// fetch fresh data | |
var networkUpdate = fetch('/data.json').then(function(response) { | |
return response.body.asJSON(); | |
}).then(function(data) { | |
networkDataReceived = true; | |
updatePage(); | |
}); | |
// fetch cached data | |
caches.match('/data.json').then(function(response) { | |
return response.body.asJSON(); | |
}).then(function(data) { | |
if (!networkDataReceived) { | |
updatePage(data); | |
} | |
}).catch(function() { | |
// we didn't get cached data, the network is our last hope: | |
return networkUpdate; | |
}).catch(showErrorMessage).then(stopSpinner); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment