You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var networkDataReceived = false;
startSpinner();
// fetch fresh data
var networkUpdate = fetch('/data.json').then(function(response) {
return response.json();
}).then(function(data) {
networkDataReceived = true;
updatePage(data);
});
// fetch cached data
caches.match('/data.json').then(function(response) {
if (!response) throw Error("No data");
return response.json();
}).then(function(data) {
// don't overwrite newer network data
if (!networkDataReceived) {
updatePage(data);
}
})
.catch(function() {
// we didn't get cached data, the network is our last hope:
return networkUpdate;
})
.catch(showErrorMessage) // never called, because previous catch swallows thrown error
.then(stopSpinner()); // stopSpinner called immediately, should be `then(stopSpinner)`.
See comments for last 2 lines of above snippet
If there is better place to report this problem, please let me know. I'll move it.
The text was updated successfully, but these errors were encountered:
Sorry for the slow response. Yeah that doesn't look right to me, we are currently in a bit of publishing limbo but I will leave this open so I can make a fix once publishing is sorted. Thanks for reporting this!
https://developers.google.com/web/ilt/pwa/caching-files-with-service-worker#serving_files_from_the_cache
Cache then network example.
See comments for last 2 lines of above snippet
If there is better place to report this problem, please let me know. I'll move it.
The text was updated successfully, but these errors were encountered: