mirror of
https://github.com/hanzoai/workbox.git
synced 2026-09-24 17:04:35 +00:00
* The contents of v3, reconciled with master. * Remove a few stray files. * Another extra file. * Two more deletions. * Setting up for stable release * v3.0.0 * Updating CDN and versions * Doc repair for wf (#1358) * Changing doc structure to work with WF * Changing doc structure to work with WF
33 lines
704 B
Handlebars
33 lines
704 B
Handlebars
{{{WORKBOX_SW_IMPORT}}}
|
|
|
|
const cacheable = new workbox.cacheableResponse.CacheableResponse({
|
|
statuses: [200],
|
|
headers: {
|
|
'X-Is-Cacheable': 'true',
|
|
},
|
|
});
|
|
|
|
const handleCachableResponse = (event) => {
|
|
return fetch(event.request)
|
|
.then((response) => {
|
|
if (cacheable.isResponseCacheable(response)) {
|
|
// Response meets the criteria
|
|
} else {
|
|
// Response does not meet the criteria
|
|
}
|
|
|
|
return response;
|
|
});
|
|
};
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
switch (new URL(event.request.url).pathname) {
|
|
case '/api/is-response-cacheable':
|
|
event.respondWith(handleCachableResponse(event));
|
|
break;
|
|
}
|
|
});
|
|
|
|
workbox.skipWaiting();
|
|
workbox.clientsClaim();
|