2

I'm reading about BroadcastChannel API https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel . It seems that it is already on market for a long time, and quite cool as well. However, what still bugging me is any practical use case that we really need this BroadcastChannel. Appreciate if there is any real life use case.

I read a lot of tutorial and most of them using BroadcastChannel to solve authentication problem, which means that if user open 10 tabs of the same page, log out of 1 them will also log out all tabs.

However, I feel this can easily be done via cookies checking, or localStorage listener. Is there any other use case that more suitable for BroadcastChannel , or am I missing something here. Thanks

1 Answer 1

1

In other contexts I've heard this described as a "Multicast Delegate" or "Event Aggregator." Its purpose is to provide decoupled, active communication between software modules using a subscriber model, and to allow multiple receivers.

enter image description here

Cookies are a passive mechanism. You can do it with a storage event, but you bind yourself tightly to the local storage mechanism. It's kind of like the difference between hot-wiring your car and using a proper key.

MDN notes that this feature can be used with Web Workers, which is a great way to delegate some work to new threads.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.