What I Didn't Know About XHR

by Mark Pruett


Years ago, I worked in a small group that occasionally needed technical information from a second group. I was young and naive, and believed that if a person said "yes, the proper setting for the frobnitz is 34.128" then setting the frobnitz to 34.128 was the Right Thing To Do.



I quickly found out that some members of that group were more than happy to supply you with an answer to any question you asked, regardless of whether they knew the answer or not. And those guys would speak as authoritatively when spinning a tale from whole cloth as they would when providing information that actually intersected with reality.



The words "I don't know" were not in their vocabulary.



Beyond a mistrust for anything these guys said, I also learned the importance of those three words. There's no crime in not knowing the answer to every question. Since those days, I've tried to be clear with people when I didn't know something. I've had many opportunities for clarity.


8 Comments

Gavri Fernandez
2006-10-15 23:41:44
The 2-connection limit is specific to IE. Opera has a default limit of 8 and the Firefox limit is only for Keep-Alive connections.
Gavri Fernandez
2006-10-15 23:49:37
You should have looked at network.http.max-connections-per-server which is 8 for Firefox too.


(Unless I'm missing something. Which is quite possible)

gabor
2006-10-16 03:11:44
the part of the RFC you mentioned deals with persistent-connections (Keep-Alive connections).


so one solution is to not do Keep-Alive connections. (that can be set up in the server)

Mark Pruett
2006-10-16 06:38:13
Gavri and gabor,


Thanks for the comments. I've been doing some experiments with Firefox, and I've found out a couple of interesting things based on gabor's Keep-Alive reference. Firefox has another setting, a boolean called "network.http.keep-alive", that's set to true by default. Using the Firefox "Live HTTP Headers" extension to examine the HTTP headers, I see that all XHR requests go out with the "Keep-Alive: 300" header set. This makes them persistent connections and subject to the default Firefox "two connection rule". Setting network.http.keep-alive to false makes the connections non-persistent and allows the eight connections you'd expect.


gabor: Turning Keep-Alive off on the server side seems to have no effect. I'm firing off five requests on the client side (Firefox) before ever receiving a response from the server. So Firefox (by default at least) assumes they're persistent and queues them up accordingly.


Kae Verens
2006-11-02 09:00:32
I have a few live-search widgets in production, which work similar to the Google Suggest method above. The way I reduce the load in that case is to set a timer of 500ms, which is reset whenever the user types another letter. This means that the result is actually grabbed just after the user stops typing.


On the idea of bundling multiple requests into one single request. Yes, that works fantastically! See here for a demo I made in August: http://verens.com/archives/2006/08/29/kaejax-demoed/
How the above works is to wait a single millisecond before sending off the request. if another request come in, then it is added to the array of requests, and the timer is reset again to one millisecond.

ballenger
2007-06-15 16:19:38
Thanks for the article
ballenger

2007-07-10 17:09:44
This is an excellent reading keep up the good writing and thanks
haase
Chris
2007-10-04 07:06:56
Mark, thanks for the article! What about calling setRequestHeader("Connection", "close") on the XMLHttpRequest object? That seems to make the connection exempt from the "two connection rule" much like setting network.http.keep-alive to false except you don't have to update the browser.