Skip to content

Instantly share code, notes, and snippets.

@JBreit
Created May 31, 2017 00:51
Show Gist options
  • Save JBreit/5a3d710c76f02a59b20e59da710000a7 to your computer and use it in GitHub Desktop.
Save JBreit/5a3d710c76f02a59b20e59da710000a7 to your computer and use it in GitHub Desktop.
const strategies = {
cacheFirst(request) {
return caches.open(APPLICATION_CACHE).then((cache) => {
return cache.match(request).then((matching) => {
return matching || Promise.reject('no-match');
});
});
},
networkFirst(request, delay) {
return new Promise((resolve, reject) => {
let timeout = setTimeout(reject, delay);
fetch(request).then((response) => {
clearTimeout(timeout);
resolve(response);
}, reject);
});
},
cacheFirstThenNetwork() {}
};
export default strategies;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment