Apia saysShared Workers serve multiple tabs of the same origin from a single worker instance.
Where a regular worker belongs to one page, a SharedWorker is shared across all tabs/windows of an origin — one instance, connected through ports. Useful for a single shared connection (one WebSocket feeding every tab) or centralized state. Support is less universal than dedicated workers, so feature-detect.
Power-ups you unlock
One worker shared across same-origin tabs
Connect via ports (port.start, postMessage)
Good for one shared connection/state
Less universal support — feature-detect
Legacy Larry attacks — common mistakes
Assuming universal browser support
Forgetting port.start()
Using SharedWorker where a dedicated one fits
Boss battleUnderstand when a SharedWorker (one shared connection) beats per-tab workers.
Example code
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>const sw = new SharedWorker('shared.js');
sw.port.start();
sw.port.postMessage('hi');
sw.port.onmessage = e => console.log(e.data);
// one instance serves every tab of this origin</pre></body></html>