workbox-broadcast-update
Summary
- Types
- Methods
Types
BroadcastCacheUpdate
Uses the postMessage()
API to inform any open windows/tabs when a cached response has been updated.
For efficiency's sake, the underlying response bodies are not compared; only specific response headers are checked.
Properties
- constructor
function
Construct a BroadcastCacheUpdate instance with a specific
channelName
to broadcast messages onThe
constructor
function looks like:(options?: BroadcastCacheUpdateOptions) => {...}
- options
BroadcastCacheUpdateOptions optional
- returns
- notifyIfUpdated
function
Compares two Responses and sends a message (via
postMessage()
) to all window clients if the responses differ. Neither of the Responses can be opaque.The message that's posted has the following format (where
payload
can be customized via thegeneratePayload
option the instance is created with):{ type: 'CACHE_UPDATED', meta: 'workbox-broadcast-update', payload: { cacheName: 'the-cache-name', updatedURL: 'https://example.com/' } }
The
notifyIfUpdated
function looks like:(options: CacheDidUpdateCallbackParam) => {...}
- options
- returns
Promise<void>
Resolves once the update is sent.
BroadcastCacheUpdateOptions
Properties
- headersToCheck
string[] optional
- notifyAllClients
boolean optional
- generatePayload
function optional
The
generatePayload
function looks like:(options: CacheDidUpdateCallbackParam) => {...}
- options
- returns
Record<stringany>
BroadcastUpdatePlugin
This plugin will automatically broadcast a message whenever a cached response is updated.
Properties
- constructor
function
Construct a
workbox-broadcast-update.BroadcastUpdate
instance with the passed options and calls itsnotifyIfUpdated
method whenever the plugin'scacheDidUpdate
callback is invoked.The
constructor
function looks like:(options?: BroadcastCacheUpdateOptions) => {...}
- options
BroadcastCacheUpdateOptions optional
- returns
Methods
responsesAreSame
workbox-broadcast-update.responsesAreSame(
firstResponse:
Response,
secondResponse:
Response,
headersToCheck:
string[],
)
Given two Response's
, compares several header values to see if they are the same or not.
Parameters
- firstResponse
Response
- secondResponse
Response
- headersToCheck
string[]
Returns
boolean