workbox. precaching
Most consumers of this module will want to use the precacheAndRoute() method to add assets to the Cache and respond to network requests with these cached assets.
If you require finer grained control, you can use the PrecacheController to determine when performed.
Class
PrecacheController
Performs efficient precaching of assets.
Methods
addRoute
addRoute(options)
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
|
precache
precache(entries)
Add items to the precache list, removing any duplicates and store 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
precacheAndRoute(entries, options)
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. |
suppressWarnings
suppressWarnings(suppress)
Warnings will be logged if any of the precached assets are entered without a revision
property. This is extremely dangerous if the URL's aren't revisioned. However, the warnings can be supressed with this method.
Parameter |
|
---|---|
suppress |
boolean |
Abstract types
CleanupResult
Object
Properties
Parameter |
|
---|---|
deletedCacheRequests |
Array of string List of URLs that were deleted from the precache cache. |
deletedRevisionDetails |
Array of string List of URLs that were deleted from the precache cache. |
InstallResult
Object
Properties
Parameter |
|
---|---|
updatedEntries |
Array of (module:workbox-precaching.PrecacheController.PrecacheEntry or string) List of entries supplied for precaching that were precached. |
notUpdatedEntries |
Array of (module:workbox-precaching.PrecacheController.PrecacheEntry or string) List of entries supplied for precaching that were already precached. |
PrecacheEntry
Object
Properties
Parameter |
|
---|---|
url |
string URL to precache. |
revision |
string Revision information for the URL. |