Constructor

BroadcastCacheUpdate

new BroadcastCacheUpdate(input)

Dispatches cache update messages when a cached response has been updated. Messages will be dispatched on a broadcast channel with the name provided as the channelName parameter.

Parameter

input

Object

Example

<caption>Using BroadcastCacheUpdate to compare a cached and fetched
request.</caption>

const url = '/path/to/file';
const cacheName = 'my-runtime-cache';

const bcu = new workbox.broadcastCacheUpdate.BroadcastCacheUpdate({
  channelName: 'cache-updates'
});

caches.open(cacheName)
.then((openCache) => {
  return Promise.all([
    cache.match(url),
    fetch(url)
  ]);
})
.then((responses) => {
  const cachedResponse = responses[0];
  const fetchedResponse = responses[1];
  if (cachedResponse) {
    bcu.notifyIfUpdated({
      cacheName,
      cachedResponse,
      fetchedResponse
    });
  }
});

Method

notifyIfUpdated

notifyIfUpdated(input)

An explicit method to call from your own code to trigger the comparison of two Responses and send a message via the Broadcast Channel API if they differ.

Parameter

input

Object

The input object to this function.