Dear my web developer friends: Hi. I’m building an AJAX application and I have some Javascript questions. Yes, if I were an earlier version of myself I’d stop reading now too.
The application is intended for use by small groups of people–say, two to ten–collaboratively, for a few hours at a time. There may be many small groups working simultaneously, but activity won’t overlap among groups, only among members of a given group.
Say Alice, Esha and Mallory are using the application, which means having the page open in a tab or window. Each of them has a panel on that page showing what the other two are up to. Alice has five heads-up tokens, and she flips two of them over; I want Esha and Mallory to see that her tokens now consist of three heads and two tails within a few seconds of her doing so. This should not require any activity on Esha’s or Mallory’s parts except having the application page open.
I’m building this with Javascript and PHP/MySQL, no Java applets or anything. Is there any way to accomplish what I want that doesn’t involve polling–that is, using setTimeOut(XMLHttpRequest(…)) to refresh the activity panels every five seconds? setTimeOut is nonblocking on the client side, but that’s a huge number of requests per time period and it scales horribly.
I’m considering the obvious optimizations (having the client side taper off in request frequency during periods of inactivity, and writing the activity data to static files so I don’t have to hit PHP and MySQL with every request). Like most optimizations, though, they don’t address the central problem of nonscalable methodology. Is there anything in Javascript that would let the client accept pings from the server side when the data updates? I don’t think there is, but I’m hoping I’m wrong.