Constructor

CacheableResponse

new CacheableResponse(input)

Creates a new Plugin instance, which stores configuration and logic to determine whether a Response object is cacheable or not.

If multiple criteria are present (e.g. both statuses and headers), then the Response needs to meet all of the criteria to be cacheable.

Parameter

input

Object

Values in input have the following properties:

Parameter

statuses

Optional

Array of Number

The status codes that are checked when determining whether a Response is cacheable.

headers

Optional

Object with String properties

The header values that are checked when determining whether a Response is cacheable.

Example

new workbox.cacheableResponse.CacheableResponse({
  statuses: [0, 200, 404],
  headers: {
    'Example-Header-1': 'Header-Value-1'
    'Example-Header-2': 'Header-Value-2'
  }
})

Method

isResponseCacheable

isResponseCacheable(input) returns boolean

Checks a response to see whether it's cacheable or not, based on the configuration of this object.

Parameter

input

Object

Values in input have the following properties:

Parameter

response

Response

The response that might be cached.

request

Optional

Request

Optionally, the request that led to the response.

Returns

boolean true if the Response is cacheable, based on the configuration of this object, and false otherwise.