I have a situation where my site needs to quickly retrieve data from my server through AJAX.
My site runs on port 80, serving regular web pages. I usually run my AJAX server on port 8001 (I use JSONP, and this works fine). This works for most users. However, some users are blocked from high ports by local firewalls.
To block users who have outgoing connections on port 8001 to use my site, I want to return to port 80 if the user cannot get a response to port 8001.
The reason I don't use port 80 all the time is because sometimes people have smart antivirus gateways or other application-level firewalls that intercept outgoing connections on port 80. They add a couple of hundred milliseconds to my time in both ends. My AJAX service should minimize round-trip response time.
I use jQuery to make XMLHttpRequest easier to use. I use the JSONP option, and this part works - pulling AJAX requests from a different IP address or port is not a problem in itself.
The idea I have is that when the page loads first, it launches 2 getJSON calls. One on port 8001, and the other on port 80. The same response handler is used in both calls.
The first call to the response handler sets my variable "portToUse" and then works with normal functionality.
This works when port 8001 is not blocked. If port 8001 is blocked, this also works. However, a delay of 5 seconds before my reply from port 80 returns. This is not called by the server. I would like to eliminate this delay.
My theory is that although getJSON is asynchronous, the browser only runs one XMLHttpRequest at a time. He waits until the first one either returns or the time runs out before sending the next one.
I'm not sure if I'm right. If so, is there a way around this functionality and turn off both XMLHttpRequest at the same time? If I am mistaken, do you have a suggestion as to what might cause a delay in receiving my second response (from port 80 on my server)? Any other suggestions are welcome.
EDIT: This behavior is only observed in Firefox 3 and Opera 9.63. IE7 and Chrome do not show this delay.