Constructor

NetworkFirst

new NetworkFirst(options)

Parameter

options

Object

Values in options have the following properties:

Parameter

cacheName

string

Cache name to store and retrieve requests. Defaults to cache names provided by workbox-core.

plugins

string

Plugins to use in conjunction with this caching strategy.

fetchOptions

Object

Values passed along to the init of all fetch() requests made by this strategy.

networkTimeoutSeconds

number

If set, any network requests that fail to respond within the timeout will fallback to the cache.

This option can be used to combat " lie-fi" scenarios.

Methods

handle

async

handle(input) returns Promise containing Response

This method will perform a request strategy and follows an API that will work with the Workbox Router.

Parameter

input

Object

Values in input have the following properties:

Parameter

event

FetchEvent

The fetch event to run this strategy against.

Returns

Promise containing Response 

makeRequest

async

makeRequest(input) returns Promise containing Response

This method can be used to perform a make a standalone request outside the context of the Workbox Router.

See "Advanced Recipes" for more usage information.

Parameter

input

Object

Values in input have the following properties:

Parameter

request

(Request or string)

Either a Request object, or a string URL, corresponding to the request to be made.

event

Optional

FetchEvent

If provided, event.waitUntil() will be called automatically to extend the service worker's lifetime.

Returns

Promise containing Response