class
Token that can be used to provide options for ServiceWorkerModule
outside of ServiceWorkerModule.register()
.
abstract class SwRegistrationOptions { enabled?: boolean scope?: string registrationStrategy?: string | (() => Observable<unknown>) }
You can use this token to define a provider that generates the registration options at runtime, for example via a function call:
import {NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {ServiceWorkerModule, SwRegistrationOptions} from '@angular/service-worker'; /* . . . */ @NgModule({ /* . . . */ imports: [ BrowserModule, ServiceWorkerModule.register('ngsw-worker.js'), ], providers: [ { provide: SwRegistrationOptions, useFactory: () => ({enabled: location.search.includes('sw=true')}), }, ], }) export class AppModule { }
Property | Description |
---|---|
enabled?: boolean | Whether the ServiceWorker will be registered and the related services (such as Default: true |
scope?: string | A URL that defines the ServiceWorker's registration scope; that is, what range of URLs it can control. It will be used when calling ServiceWorkerContainer#register(). |
registrationStrategy?: string | (() => Observable<unknown>) | Defines the ServiceWorker registration strategy, which determines when it will be registered with the browser. The default behavior of registering once the application stabilizes (i.e. as soon as there are no pending micro- and macro-tasks) is designed to register the ServiceWorker as soon as possible but without affecting the application's first time load. Still, there might be cases where you want more control over when the ServiceWorker is registered (for example, there might be a long-running timeout or polling interval, preventing the app from stabilizing). The available option are:
Default: 'registerWhenStable:30000' |
© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/service-worker/SwRegistrationOptions