Reference · print-friendly

BroadcastChannel decision playbook

One page for design reviews. Walk top to bottom; stop when a row rejects the current candidate.

1. Gate A · Job (which multi-context tool?)

If… Prefer…
Same-origin peers must hear a signal and act locally (logout, theme, invalidate) BroadcastChannel
One process must own a scarce resource (socket, engine, shared memory-ish coordinator) SharedWorker
One page CPU offload only Dedicated Worker
Offline shell / fetch policy / push control plane Service worker (+ Cache)
Tab-private sticky state for a page session sessionStorage / memory — not a bus
Tiny durable prefs; optional crude multi-tab localStorage (+ storage events as legacy bus)
Cross-origin messaging window.postMessage / MessageChannel — not BC

2. Gate B · Wire (if BroadcastChannel)

3. Gate C · Truth & late joiners

4. Gate D · Ship risks

Sentence to say in review

“We use BroadcastChannel | SharedWorker | sessionStorage | SW | … because job; wire is name + local-then-post + small clone; truth is store/server; we own origin · support · no lock myth · close hygiene.”

5. Mini API crib

const ch = new BroadcastChannel("app:sync");
ch.onmessage = (e) => handle(e.data);
function publish(msg) {
  handle(msg); // local — sender excluded
  ch.postMessage(msg);
}
// teardown: ch.close();