Merge pull request #70 from akihikodaki/master

Do not cache with Cache API if cache mode is only-if-cached
This commit is contained in:
Rich Harris
2018-07-22 17:56:39 -04:00
committed by GitHub

View File

@@ -58,6 +58,8 @@ self.addEventListener('fetch', event => {
} }
*/ */
if (event.request.cache === 'only-if-cached') return;
// for everything else, try the network first, falling back to // for everything else, try the network first, falling back to
// cache if the user is offline. (If the pages never change, you // cache if the user is offline. (If the pages never change, you
// might prefer a cache-first approach to a network-first one.) // might prefer a cache-first approach to a network-first one.)
@@ -66,11 +68,6 @@ self.addEventListener('fetch', event => {
.open(`offline${timestamp}`) .open(`offline${timestamp}`)
.then(async cache => { .then(async cache => {
try { try {
if (event.request.cache === 'only-if-cache') {
// workaround Chrome devtools bug https://github.com/sveltejs/sapper-template/issues/34
event.request.mode = 'same-origin';
}
const response = await fetch(event.request); const response = await fetch(event.request);
cache.put(event.request, response.clone()); cache.put(event.request, response.clone());
return response; return response;