Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@angular/service-worker
Advanced tools
@angular/service-worker is an Angular package that provides support for service workers in Angular applications. It allows you to leverage the power of service workers to enable features like offline capabilities, background data synchronization, and push notifications in your Angular applications.
Offline Capabilities
This feature allows your Angular application to work offline by caching resources. The ServiceWorkerModule is registered with the service worker script 'ngsw-worker.js', and it is enabled based on the environment configuration.
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Background Data Synchronization
This feature allows your application to synchronize data in the background. The SwUpdate service is used to check for updates and prompt the user to reload the application when a new version is available.
import { SwUpdate } from '@angular/service-worker';
constructor(private updates: SwUpdate) {
this.updates.available.subscribe(event => {
if (confirm('New version available. Load New Version?')) {
window.location.reload();
}
});
}
Push Notifications
This feature allows your application to receive push notifications. The SwPush service is used to request a subscription to push notifications using a VAPID key.
import { SwPush } from '@angular/service-worker';
constructor(private swPush: SwPush) {
this.swPush.requestSubscription({
serverPublicKey: 'YOUR_PUBLIC_VAPID_KEY'
}).then(subscription => {
// Send subscription to the server
}).catch(err => console.error('Could not subscribe to notifications', err));
}
Workbox is a set of libraries and Node modules that make it easy to cache assets and take full advantage of features used to build Progressive Web Apps. Compared to @angular/service-worker, Workbox provides more flexibility and is framework-agnostic, making it suitable for a wider range of projects beyond Angular.
sw-precache is a library for generating service worker code that precaches resources to make your web app work offline. It is less integrated with specific frameworks like Angular but offers a straightforward way to implement service workers in any web application.
sw-toolbox provides a set of tools for handling network requests with service workers. It is more focused on runtime caching strategies compared to @angular/service-worker, which offers a more comprehensive solution for Angular applications.
The sources for this package are in the main Angular repo. Please file issues and pull requests against that repo.
Usage information and reference details can be found in Angular documentation.
License: MIT
19.0.0-next.8 (2024-10-02)
| Commit | Type | Description | | -- | -- | -- | | c3115b882e | fix | execute checks and remove placeholder when image is already loaded (#55444) | | b7bd429951 | fix | prevent warning about oversize image twice (#58021) | | e8b2d5fad8 | fix | skip checking whether SVGs are oversized (#57966) |
| Commit | Type | Description | | -- | -- | -- | | d9687f43dd | feat | 'strictStandalone' flag enforces standalone (#57935) | | 39ccaf4cc4 | fix | correctly get the type of nested function call expressions (#57010) | | 33fe252c58 | fix | do not report unused declarations coming from an imported array (#57940) |
| Commit | Type | Description | | -- | -- | -- | | 3240598158 | fix | provide flag to opt into manual cleanup for after render hooks (#57917) |
| Commit | Type | Description | | -- | -- | -- | | 22dafa658b | fix | cleanup JSONP script listeners once loading completed (#57877) | | 057cf7fb6b | fix | preserve all headers from Headers object (#57802) |
| Commit | Type | Description | | -- | -- | -- | | 5c4305f024 | feat | support migrating full classes to signal inputs in VSCode (#57975) |
| Commit | Type | Description | | -- | -- | -- | | b6bc93803c | feat | add schematic to migrate to signal queries (#58032) | | ef577b2d2b | fix | delete constructor if it only has super call (#58013) |
| Commit | Type | Description | | -- | -- | -- | | 5f56a65837 | fix | support input signal bindings (#57020) |
<!-- CHANGELOG SPLIT MARKER --><a name="18.2.7"></a>
FAQs
Angular - service worker tooling!
The npm package @angular/service-worker receives a total of 409,011 weekly downloads. As such, @angular/service-worker popularity was classified as popular.
We found that @angular/service-worker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.