workbox-cacheable-response

Given a Response object this library determines whether it's "cacheable", based on the response's status code and / or header values.

Most develpers will use this module by instantiating a new CachaebleResponsePlugin and passing it to a RequestWrapper, as shown in the example below.

Example

Using the CachaebleResponsePlugin class in a service worker.

// The responses will be cached if the response code is 0, 200, or 404, and
// will not be cached otherwise.
const cacheablePlugin = new workbox.cacheableResponse.Plugin({
  statuses: [0, 200, 404]
});

const requestWrapper = new workbox.runtimeCaching.RequestWrapper({
  cacheName: 'runtime-cache',
  plugins: [
    cacheablePlugin
  ]
});

const route = new workbox.routing.RegExpRoute({
  match: ({url}) => url.domain === 'example.com',
  handler: new workbox.runtimeCaching.StaleWhileRevalidate({requestWrapper})
});

Classes

CacheableResponse
CacheableResponsePlugin