---
url: /api/symbols/workbox-swkit/broadcast-update/broadcastcacheupdate.md
---

# BroadcastCacheUpdate

Class @vite-pwa/workbox-swkit/broadcast-update

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.

## Constructor

```ts
new BroadcastCacheUpdate(options?: BroadcastCacheUpdateOptions)
```

Construct a BroadcastCacheUpdate instance with a specific `channelName` to
broadcast messages on

## Methods

### notifyIfUpdated()

```ts
notifyIfUpdated(options: CacheDidUpdateCallbackParam): Promise<void>
```

Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
and sends a message (via `postMessage()`) to all window clients if the
responses differ. Neither of the Responses can be
[opaque](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).

The message that's posted has the following format (where `payload` can
be customized via the `generatePayload` option the instance is created
with):

```
{
  type: 'CACHE_UPDATED',
  meta: 'workbox-broadcast-update',
  payload: {
    cacheName: 'the-cache-name',
    updatedURL: 'https://example.com/'
  }
}
```

**Returns:** Resolves once the update is sent.
