Commit 01f4b244 authored by Julien Enselme's avatar Julien Enselme

Cache response based on Cache-Control header

If it contains no-cache, the response will not be cached.
parent 506bfa75
......@@ -96,9 +96,14 @@ function fetchAndSaveInCache(event, cacheName) {
return fetch(event.request)
.then(res => {
const requestSucceeded = res.status >= 200 && res.status <= 300;
const cacheHeader = res.headers.get('cache-control') || [];
const mustNotCache = cacheHeader.includes('no-cache');
if (!requestSucceeded) {
console.log('[SW] Request failed.');
return res;
} else if (mustNotCache) {
console.log('[SW] The page must not be cached.');
return res;
}
return caches.open(cacheName)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment