workbox-core
All of the Workbox service worker libraries use workbox-core for shared code as well as setting default values that need to be shared (like cache names).
Property
cacheNames
Get the current cache names and prefix/suffix used by Workbox.
cacheNames.precache
is used for precached assets,
cacheNames.googleAnalytics
is used by workbox-google-analytics
to
store analytics.js
, and cacheNames.runtime
is used for everything else.
cacheNames.prefix
can be used to retrieve just the current prefix value.
cacheNames.suffix
can be used to retrieve just the current suffix value.
- Returns
-
Object
An object withprecache
,runtime
,prefix
, andgoogleAnalytics
properties.
Methods
clientsClaim
clientsClaim()
Claim any currently available clients once the service worker
becomes active. This is normally used in conjunction with skipWaiting()
.
copyResponse
copyResponse(response, modifier)
Allows developers to copy a response and modify its headers
, status
,
or statusText
values (the values settable via a
ResponseInit
object in the constructor).
To modify these values, pass a function as the second argument. That
function will be invoked with a single object with the response properties
{headers, status, statusText}
. The return value of this function will
be used as the ResponseInit
for the new Response
. To change the values
either modify the passed parameter(s) and return it, or return a totally
new object.
This method is intentionally limited to same-origin responses, regardless of whether CORS was used or not.
Parameter |
|
---|---|
response |
Response |
modifier |
function() |
registerQuotaErrorCallback
registerQuotaErrorCallback(callback)
Adds a function to the set of quotaErrorCallbacks that will be executed if there's a quota error.
Parameter |
|
---|---|
callback |
function() |
setCacheNameDetails
setCacheNameDetails(details)
Modifies the default cache names used by the Workbox packages.
Cache names are generated as <prefix>-<Cache Name>-<suffix>
.
Parameter |
|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
details |
Object Values in
|
skipWaiting
skipWaiting()
This method is deprecated, and will be removed in Workbox v7.
Calling self.skipWaiting() is equivalent, and should be used instead.