Socket
Socket
Sign inDemoInstall

workbox-broadcast-update

Package Overview
Dependencies
1
Maintainers
7
Versions
57
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    workbox-broadcast-update

A service worker helper library that uses the Broadcast Channel API to announce when a cached response has updated


Version published
Weekly downloads
4.2M
decreased by-0.13%
Maintainers
7
Install size
398 kB
Created
Weekly downloads
 

Package description

What is workbox-broadcast-update?

The workbox-broadcast-update package is part of the Workbox suite of libraries, which are designed to make service workers and offline functionality in web applications easier to implement and more robust. Specifically, workbox-broadcast-update is used to notify web app pages when a cached response has been updated. This is particularly useful for pages that are open in the browser and need to be informed about fresh data available in the cache, allowing the app to react and update the UI accordingly.

What are workbox-broadcast-update's main functionalities?

Broadcasting cache updates

This code sample demonstrates how to use the BroadcastUpdatePlugin within a service worker to automatically notify pages when a cached response from an API route has been updated. It uses the NetworkFirst strategy, meaning it tries to fetch the latest response from the network first before falling back to the cache. When a new response is fetched and cached, the BroadcastUpdatePlugin sends a message to all open pages to inform them of the update.

import {BroadcastUpdatePlugin} from 'workbox-broadcast-update';

workbox.routing.registerRoute(
  ({url}) => url.pathname.startsWith('/api'),
  new workbox.strategies.NetworkFirst({
    plugins: [
      new BroadcastUpdatePlugin()
    ],
  }),
);

Other packages similar to workbox-broadcast-update

Readme

Source

This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-broadcast-update

Keywords

FAQs

Last updated on 23 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc