Properties

addRoute

constant   static

Add a fetch listener to the service worker that will respond to network requests with precached assets.

Requests for assets that aren't precached, the FetchEvent will not be responded to, allowing the event to fall through to other fetch event listeners.

Parameter

options

Object

Values in options have the following properties:

Parameter

directoryIndex

Optional

string

The directoryIndex will check cache entries for a URLs ending with '/' to see if there is a hit when appending the directoryIndex value.

ignoreURLParametersMatching

Optional

Array of RegExp

An array of regex's to remove search params when looking for a cache match.

cleanURLs

Optional

boolean

The cleanURLs option will check the cache for the URL with a .html added to the end of the end.

urlManipulation

Optional

workbox.precaching~urlManipulation

This is a function that should take a URL and return an array of alternative URL's that should be checked for precache matches.

cleanupOutdatedCaches

constant   static

Adds an activate event listener which will clean up incompatible precaches that were created by older versions of Workbox.

getCacheKeyForURL

constant   static

Takes in a URL, and returns the corresponding URL that could be used to lookup the entry in the precache.

If a relative URL is provided, the location of the service worker file will be used as the base.

For precached entries without revision information, the cache key will be the same as the original URL.

For precached entries with revision information, the cache key will be the original URL with the addition of a query parameter used for keeping track of the revision info.

Parameter

url

string

The URL whose cache key to look up.

Returns

string The cache key that corresponds to that URL.

precache

constant   static

Adds items to the precache list, removing any duplicates and stores the files in the "precache cache" when the service worker installs.

This method can be called multiple times.

Please note: This method will not serve any of the cached files for you. It only precaches files. To respond to a network request you call addRoute().

If you have a single array of files to precache, you can just call precacheAndRoute().

Parameter

entries

Array of (Object or string)

Array of entries to precache.

precacheAndRoute

constant   static

This method will add entries to the precache list and add a route to respond to fetch events.

This is a convenience method that will call precache() and addRoute() in a single call.

Parameter

entries

Array of (Object or string)

Array of entries to precache.

options

Object

See addRoute() options.

Method

addPlugins

static

addPlugins(newPlugins)

Adds plugins to precaching.

Parameter

newPlugins

Array of Object

Abstract types

CleanupResult

static

Object

Property

Parameter

deletedCacheRequests

Array of string

List of URLs that were deleted while cleaning up the cache.

InstallResult

static

Object

Properties

Parameter

updatedURLs

Array of string

List of URLs that were updated during installation.

notUpdatedURLs

Array of string

List of URLs that were already up to date.

PrecacheEntry

static

Object

Properties

Parameter

url

string

URL to precache.

revision

Optional

string

Revision information for the URL.

urlManipulation

inner

urlManipulation(context) returns Array of URL

The "urlManipulation" callback can be used to determine if there are any additional permutations of a URL that should be used to check against the available precached files.

For example, Workbox supports checking for '/index.html' when the URL '/' is provided. This callback allows additional, custom checks.

Parameter

context

Object

Values in context have the following properties:

Parameter

url

URL

The request's URL.

Returns

Array of URL To add additional urls to test, return an Array of URLs. Please note that these should not be strings, but URL objects.