web.dev LIVE has kicked off! Join us now for our digital event from June 30th to July 2nd at web.dev/live

Class: NetworkFirst

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

Array of Object

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.

matchOptions

Object

CacheQueryOptions

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.

Method

handle

async

handle(options) returns Promise containing Response

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

Parameter

options

Object

Values in options have the following properties:

Parameter

request

(Request or string)

A request to run this strategy for.

event

Optional

Event

The event that triggered the request.

Returns

Promise containing Response