SwRegistrationOptions
Token that can be used to provide options for ServiceWorkerModule outside of
ServiceWorkerModule.register().
enabled
boolean | undefinedupdateViaCache
ServiceWorkerUpdateViaCache | undefinedThe value of the setting used to determine the circumstances in which the browser will consult the HTTP cache when it tries to update the service worker or any scripts that are imported via importScripts(). ServiceWorkerRegistration.updateViaCache
type
WorkerType | undefinedThe type of the ServiceWorker script to register. ServiceWorkerRegistration#type
classic: Registers the script as a classic worker. ES module features such asimportandexportare NOT allowed in the script.module: Registers the script as an ES module. Allows use ofimport/exportsyntax and module features.
scope
string | undefinedA 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>) | undefinedDefines 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:
registerWhenStable:<timeout>: Register as soon as the application stabilizes (no pending micro-/macro-tasks) but no later than<timeout>milliseconds. If the app hasn't stabilized after<timeout>milliseconds (for example, due to a recurrent asynchronous task), the ServiceWorker will be registered anyway. If<timeout>is omitted, the ServiceWorker will only be registered once the app stabilizes.registerImmediately: Register immediately.registerWithDelay:<timeout>: Register with a delay of<timeout>milliseconds. For example, useregisterWithDelay:5000to register the ServiceWorker after 5 seconds. If<timeout>is omitted, is defaults to0, which will register the ServiceWorker as soon as possible but still asynchronously, once all pending micro-tasks are completed.- An Observable factory function: A function that returns an
Observable. The function will be used at runtime to obtain and subscribe to theObservableand the ServiceWorker will be registered as soon as the first value is emitted.
Default: 'registerWhenStable:30000'
Description
Token that can be used to provide options for ServiceWorkerModule outside of
ServiceWorkerModule.register().
You can use this token to define a provider that generates the registration options at runtime, for example via a function call:
{@example service-worker/registration-options/module.ts region="registration-options" header="app.module.ts"}