Files
workbox/demos/functions/views/demo/workbox-cacheable-response/sw.hbs
T
Jeffrey PosnickandGitHub 9d88f2abae The contents of v3, reconciled with master (#1357)
* 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
2018-03-13 15:20:33 -04:00

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();