Socket
Socket
Sign inDemoInstall

@angular/service-worker

Package Overview
Dependencies
1
Maintainers
3
Versions
736
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@angular/service-worker

Angular - service worker tooling!


Version published
Weekly downloads
361K
increased by0.71%
Maintainers
3
Install size
501 kB
Created
Weekly downloads
 

Package description

What is @angular/service-worker?

@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.

What are @angular/service-worker's main functionalities?

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));
}

Other packages similar to @angular/service-worker

Readme

Source

Angular

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

FAQs

Last updated on 09 Dec 2021

Did you know?

Socket

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc