Created
May 31, 2017 00:51
-
-
Save JBreit/5a3d710c76f02a59b20e59da710000a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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