Didn't make the #ChromeDevSummit this year? Catch all the content (and more!) in the Chrome Dev Summit 2019 playlist on our Chrome Developers YouTube Channel.

Class: PrecacheController

Constructor

PrecacheController

new PrecacheController(cacheName)

Create a new PrecacheController.

Parameter

cacheName

Optional

string

An optional name for the cache, to override the default precache name.

Methods

activate

async

activate() returns Promise containing workbox.precaching.CleanupResult

Deletes assets that are no longer present in the current precache manifest. Call this method from the service worker activate event.

Returns

Promise containing workbox.precaching.CleanupResult 

addToCacheList

addToCacheList(entries)

This method will add items to the precache list, removing duplicates and ensuring the information is valid.

Parameter

entries

Array of (module:workbox-precaching.PrecacheController.PrecacheEntry or string)

Array of entries to precache.

getCachedURLs

getCachedURLs() returns Array of string

Returns a list of all the URLs that have been precached by the current service worker.

Returns

Array of string The precached URLs.

getCacheKeyForURL

getCacheKeyForURL(url) returns string

Returns the cache key used for storing a given URL. If that URL is unversioned, like `/index.html', then the cache key will be the original URL with a search parameter appended to it.

Parameter

url

string

A URL whose cache key you want to look up.

Returns

string The versioned URL that corresponds to a cache key for the original URL, or undefined if that URL isn't precached.

getURLsToCacheKeys

getURLsToCacheKeys() returns Object with string properties

Returns a mapping of a precached URL to the corresponding cache key, taking into account the revision information for the URL.

Returns

Object with string properties A URL to cache key mapping.

install

async

install(options) returns Promise containing workbox.precaching.InstallResult

Precaches new and updated assets. Call this method from the service worker install event.

Parameter

options

Object

Values in options have the following properties:

Parameter

event

Optional

Event

The install event (if needed).

plugins

Optional

Array of Object

Plugins to be used for fetching and caching during install.

Returns

Promise containing workbox.precaching.InstallResult