I found out that SE is using "simple" polling, but I wonder how SE chat works when multiple tabs in the same browser context are opened. When I open two or more tabs with some chat rooms it looks like (through developer tools) only one tab keeps active polling (obviously checking https://chat.stackoverflow.com/events for changes) and the others are "silent" (although I can see sporadic errors regarding polling and sometimes actively polling tab "change" their polling duty with other silent tab).

  • do you somehow synchronize events between silent tabs and the active one which is polling for changes?
  • I'm wrong and you are hitting parallel connections limit?
  • I'm completely wrong and some other (non-secret) magic is involved?

1 Answer 1


You're absolutely correct; if your browser supports the HTML DOM storage (and all reasonably modern browsers do), we utilize it as a communication mechanism between several open tabs on the same chat site. The main purpose is indeed having only one window do the polling (saving network traffic for both your browser and our server).

  • That's interesting because for example Facebook is using unique (sub)domain for each long polling tab (to overcome parallel connections limit). What about the browsers which do not support this type of storage? Do you have some fallback solution or they are excluded from chat functionality?
    – yojimbo87
    Mar 28, 2011 at 14:45
  • @yojimbo87: No, this functionality is optional. If the browser doesn't support it, every tab will poll. You can try it out in Firefox by setting dom.storage.enabled to false in about:config, for example. Also, since we currently don't use long polling, the parallel connections thing isn't really an issue for us.
    – balpha StaffMod
    Mar 28, 2011 at 14:48
  • So what you basically do is that client tab periodically (with some constant timeout) checks the server for changes and reflect whatever is returned to other tabs through local storage.
    – yojimbo87
    Mar 28, 2011 at 15:01
  • Is this still correct? Because dom storage is synchronous and definitely not meant to do this. We have shared workers which will work way better and are available in most sane browsers (you can always use dom storage as a fallback). Jul 18, 2015 at 21:22
  • @AwalGarg Storage events, which is what's used here, are completely asynchronous. We don't care about what's currently stored in the storage, instead we listen for notifications that the content has changed. See bitbucket.org/balpha/bytheway.js/src if you're curious about the details.
    – balpha StaffMod
    Jul 19, 2015 at 12:47
  • could you please give an example of how to do messaging between windows using dom storage? I don't dom storage has events/callbacks.
    – brauliobo
    Oct 1, 2015 at 22:39
  • @brauliobo developer.mozilla.org/en/docs/Web/API/StorageEvent. Also see my library that I linked in the comment above.
    – balpha StaffMod
    Oct 2, 2015 at 4:22
  • If I may ask, what's the algorithm (or code) for electing which of several browser tabs is the master/active tab, which contains/does the polling? If there are several tabs and the master/active tab is closed, which of the several slave/silent tabs is elected (or self-selected) to become the new master? How do you detect when the master shuts down (e.g. do you hook the window's unload or beforeunload events, and/or do you poll)?
    – ChrisW
    Aug 6, 2016 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .