W3cubDocs

/Angular

@angular/service-worker

package

Implements a service worker for Angular apps. Adding a service worker to an Angular app is one of the steps for turning it into a Progressive Web App (also known as a PWA).

At its simplest, a service worker is a script that runs in the web browser and manages caching for an application. Service workers function as a network proxy. They intercept all outgoing HTTP requests made by the application and can choose how to respond to them.

To set up the Angular service worker in your project, use the CLI add command.

ng add @angular/pwa

The command configures your app to use service workers by adding the service-worker package and generating the necessary support files.

For more usage information, see the Service Workers guide.

Entry points

Primary

@angular/service-worker

Implements a service worker for Angular apps. Adding a service worker to an Angular app is one of the steps for turning it into a Progressive Web App (also known as a PWA).

Primary entry point exports

NgModules

ServiceWorkerModule

Classes

SwPush

Subscribe and listen to Web Push Notifications through Angular Service Worker.

SwRegistrationOptions

Token that can be used to provide options for ServiceWorkerModule outside of ServiceWorkerModule.register().

SwUpdate

Subscribe to update notifications from the Service Worker, trigger update checks, and forcibly activate updates.

Functions

provideServiceWorker

Structures

NoNewVersionDetectedEvent

An event emitted when the service worker has checked the version of the app on the server and it didn't find a new version that it doesn't have already downloaded.

UnrecoverableStateEvent

An event emitted when the version of the app used by the service worker to serve this client is in a broken state that cannot be recovered from and a full page reload is required.

UpdateActivatedEvent

Deprecated: This event is only emitted by the deprecated SwUpdate#activated. Use the return value of SwUpdate#activateUpdate instead.

An event emitted when a new version of the app has been downloaded and activated.

UpdateAvailableEvent

Deprecated: This event is only emitted by the deprecated SwUpdate#available. Use the VersionReadyEvent instead, which is emitted by SwUpdate#versionUpdates. See SwUpdate#available docs for an example.

An event emitted when a new version of the app is available.

VersionDetectedEvent

An event emitted when the service worker has detected a new version of the app on the server and is about to start downloading it.

VersionInstallationFailedEvent

An event emitted when the installation of a new version failed. It may be used for logging/monitoring purposes.

VersionReadyEvent

An event emitted when a new version of the app is available.

Types

VersionEvent

A union of all event types that can be emitted by api/service-worker/SwUpdate#versionUpdates.

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/service-worker