
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
workbox-broadcast-update
Advanced tools
A service worker helper library that uses the Broadcast Channel API to announce when a cached response has updated
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.
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()
],
}),
);
sw-precache is a package that generates a service worker to precache resources of a web app. While it focuses on precaching and serving assets from the cache, it does not offer built-in functionality for broadcasting cache updates to the pages of an app like workbox-broadcast-update does. However, it can be used in conjunction with custom code to achieve similar effects.
sw-toolbox provides various caching strategies for handling network requests in service workers. Similar to workbox-broadcast-update, it aims to enhance offline capabilities and performance of web apps. However, sw-toolbox does not have a built-in mechanism for broadcasting updates about cached content to the app's pages. Developers would need to implement their own solution for notifying pages about cache updates.
This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-broadcast-update
FAQs
A service worker helper library that uses the Broadcast Channel API to announce when a cached response has updated
The npm package workbox-broadcast-update receives a total of 2,668,311 weekly downloads. As such, workbox-broadcast-update popularity was classified as popular.
We found that workbox-broadcast-update demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.