angular-docs-cn/packages/service-worker/src
Sonu Kapoor 00efacf561 feat(service-worker): support timeout in `registerWhenStable` SW registration strategy (#35870)
Previously, when using the `registerWhenStable` ServiceWorker
registration strategy (which is also the default) Angular would wait
indefinitely for the [app to stabilize][1], before registering the
ServiceWorker script. This could lead to a situation where the
ServiceWorker would never be registered when there was a long-running
task (such as an interval or recurring timeout).

Such tasks can often be started by a 3rd-party dependency (beyond the
developer's control or even without them realizing). In addition, this
situation is particularly hard to detect, because the ServiceWorker is
typically not used during development and on production builds a
previous ServiceWorker instance might be already active.

This commit enhances the `registerWhenStable` registration strategy by
adding support for an optional `<timeout>` argument, which guarantees
that the ServiceWorker will be registered when the timeout expires, even
if the app has not stabilized yet.

For example, with `registerWhenStable:5000` the ServiceWorker will be
registered as soon as the app stabilizes or after 5 seconds if the app
has not stabilized by then.

Related to #34464.

[1]: https://angular.io/api/core/ApplicationRef#is-stable-examples

PR Close #35870
2020-03-27 10:47:44 -07:00
..
index.ts feat(service-worker): expose `SwRegistrationOptions` token to allow runtime config (#21842) 2019-04-25 12:29:58 -07:00
low_level.ts refactor(service-worker): ensure compatibility with typescript strict flag (#30993) 2019-07-18 14:21:26 -07:00
module.ts feat(service-worker): support timeout in `registerWhenStable` SW registration strategy (#35870) 2020-03-27 10:47:44 -07:00
push.ts docs(service-worker): add example app for `SwPush` API docs (#32139) 2019-08-27 16:18:53 -07:00
update.ts docs: convert all `@experimental` tags to `@publicApi` tags (#26595) 2018-10-19 14:35:52 -07:00