SHARED WORKERS
A shared web worker or shared worker behaves like a dedicated worker but is accessible across multiple trusted execution contexts. For example, two different tabs on the same origin will be able to access a single web worker. SharedWorker
and Worker
feature slightly different messaging interfaces, both externally and internally.
A shared worker is valuable in situations where the developer wishes to reduce computational overhead by allowing multiple execution contexts to share a worker. An example of this could be a single shared worker managing a websocket to send and receive messages for multiple same-origin pages. Shared workers are also useful when same-origin contexts wish to communicate via the shared worker.
Shared Worker Basics
Behaviorally speaking, shared workers can be considered an extension of dedicated workers. Worker creation, worker options, security restrictions, and importScripts()
all behave in the same way. As is the case with a dedicated worker, the...