views:

347

answers:

2

I read that XMLHttpRequests are best suited for content that has an update frequency of 30 seconds or more. The same article mentioned that web apps that needed a faster frequency should use a socket. I can't find the article/book that mentions this (If anybody can post links to articles that discuss this, I would appreciate it). Does your experience with XMLHttpRequest and sockets support the above claim or not? What other types of connections between the browser and server should be considered?

+3  A: 

Javascript doesn't have a way to do true socket communications. If you're locked in to Javascript only (without a SWF helper, ActiveX, or some other tech) then XMLHttpRequest is your best bet.

XMLHttpRequest is not well suited for more frequent updates (in theory, at least) because of the overhead involved with parsing and forming the request and parsing the results. In theory, a Socket connection would give you a pipe back to the server without going through all the request generation.

The downside to using Sockets (besides the fact that Javascript doesn't support them directly) is that, if you use a custom serialization format for the data coming back over the Socket connection, only code you write can consume the results (unless you public your Serialization format). That may not be an issue for you, but for some it's a showstopper...

Here's a little demo of Sockets in Javascript with a SWF Helper:

SocketJS

Justin Niessner
+2  A: 

There is more to the answer than update frequency. The number of concurrent users is important too, as using Comet (this is the keyword that will lead you to more articles) uses up server connections and may not scale as well. Modern web servers are better at handling more connections, but you need to test this in your own environment.

For me, even 30 seconds is too often to be using AJAX. My limit is probably around the one minute mark.

RedFilter