← Back to release summary

Extended lifetime shared workers

Category
Miscellaneous
Type
New or changed feature
Status
Proposed (Chrome Proposed)
Intent stage
None

Summary

This update adds a new option, `extendedLifetime: true`, to the `SharedWorker` constructor. This new option requests that the shared worker be kept alive even after all current clients have unloaded. This allows pages to perform asynchronous work that requires JavaScript after a page unloads, without needing to rely on a service worker.

Motivation

Many sites want to perform some work during document unloading. This usually includes writing to storage, or sending information to severs. Currently, if this work is done asynchronously (e.g., writing to IndexedDB instead of localStorage, or using CompressionStream to compress the body before sending a fetch()) the only way to do this is to use a service worker. However, requiring a service worker for this simple case of work-after-unload is heavyweight: the disk space, memory consumption, and developer experience of managing the service worker registration and lifecycle makes this hard to deploy. By using shared workers, all of these downsides are avoided.

Standards & signals

Explainers: https://gist.github.com/domenic/c5bd38339f33b49120ae11b3b4af5b9b#file-1-explainer-md

View on chromestatus.com