Better cacheability checks
This commit is contained in:
parent
1aa00dacb5
commit
9d290fa645
@ -45,12 +45,22 @@ self.addEventListener('fetch', /** @param {FetchEvent} event */ async function (
|
||||
return (await cache.match(event.request)) || (await fetchedResponse);
|
||||
}
|
||||
|
||||
function isCacheable(url) {
|
||||
const pathname = new URL(url).pathname;
|
||||
return !pathname.startsWith('login')
|
||||
function isCacheable(request) {
|
||||
if (request.method !== 'GET')
|
||||
return false;
|
||||
if (request.destination === 'manifest')
|
||||
return false;
|
||||
if (request.destination === 'serviceworker')
|
||||
return false;
|
||||
if (request.url.match('oauth2'))
|
||||
return false;
|
||||
if (request.url.match('login'))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.request.method === 'GET' && isCacheable(event.request.url)) {
|
||||
if (isCacheable(event.request)) {
|
||||
console.log('interceptiing fetch', event.request.url);
|
||||
return event.respondWith(staleWhileRevalidate());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user