Skip to content

Instantly share code, notes, and snippets.

@FlorianRappl
Created July 2, 2018 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianRappl/2a97c3438f1a9d07deda9440651e0e0a to your computer and use it in GitHub Desktop.
Save FlorianRappl/2a97c3438f1a9d07deda9440651e0e0a to your computer and use it in GitHub Desktop.
async function getFromNetwork(req) {
const cache = await caches.open('data');
try {
const res = await fetch(req);
cache.put(req, res.clone());
return res;
} catch (e) {
const res = await cache.match(req);
return res || getFallback(req);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment