Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

SwUpdate

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

      
      class SwUpdate {
  versionUpdates: Observable<VersionEvent>
  unrecoverable: Observable<UnrecoverableStateEvent>
  isEnabled: boolean
checkForUpdate(): Promise<boolean>
activateUpdate(): Promise<boolean> }

See also

Provided in

Properties

Property Description
versionUpdates: Observable<VersionEvent> Read-Only

Emits a VersionDetectedEvent event whenever a new version is detected on the server.

Emits a VersionInstallationFailedEvent event whenever checking for or downloading a new version fails.

Emits a VersionReadyEvent event whenever a new version has been downloaded and is ready for activation.

unrecoverable: Observable<UnrecoverableStateEvent> Read-Only

Emits an UnrecoverableStateEvent event whenever the version of the app used by the service worker to serve this client is in a broken state that cannot be recovered from without a full page reload.

isEnabled: boolean Read-Only

True if the Service Worker is enabled (supported by the browser and enabled via ServiceWorkerModule).

Methods

Checks for an update and waits until the new version is downloaded from the server and ready for activation.

      
      checkForUpdate(): Promise<boolean>
    
Parameters

There are no parameters.

Returns

Promise<boolean>: a promise that

  • resolves to true if a new version was found and is ready to be activated.
  • resolves to false if no new version was found
  • rejects if any error occurs

Updates the current client (i.e. browser tab) to the latest version that is ready for activation.

      
      activateUpdate(): Promise<boolean>
    
Parameters

There are no parameters.

Returns

Promise<boolean>: a promise that

  • resolves to true if an update was activated successfully
  • resolves to false if no update was available (for example, the client was already on the latest version).
  • rejects if any error occurs

In most cases, you should not use this method and instead should update a client by reloading the page.

Updating a client without reloading can easily result in a broken application due to a version mismatch between the application shell and other page resources, such as lazy-loaded chunks, whose filenames may change between versions.

Only use this method, if you are certain it is safe for your specific use case.