Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 153 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

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 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?
share|improve this question
up vote 9 down vote accepted

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).

share|improve this answer
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 '11 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 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 Mar 28 '11 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 '11 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). – Awal Garg Jul 18 '15 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 if you're curious about the details. – balpha Jul 19 '15 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 '15 at 22:39
@brauliobo Also see my library that I linked in the comment above. – balpha Oct 2 '15 at 4:22

You must log in to answer this question.

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