freecoding.school100% FREE · NO SIGNUP
API ArcadeISSUE #14 of 23

shared workers · cross-tab compute

ApiaVSLegacy Larry
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

Legacy Larry attacks — common mistakes

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>
▶ Open the interactive comic issue
‹ Web Workers · PostMessage · TransferableWorklets · Paint · Audio · Animation ›