I have a situation where my website needs to quickly retrieve data from my server via AJAX.
My website runs on port 80, serving normal web pages. I normally 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 their local firewalls.
In order to allow people who have outgoing connections on port 8001 blocked to use my website, I want to fall back onto port 80 in case the user is unable to get a response on port 8001.
The reason I do not use port 80 all the time is that sometimes people have "smart" anti-virus gateways or other application level firewalls which intercept outgoing connections on port 80. These add a couple hundred milliseconds to my roundtrip time. My AJAX service needs to minimize the roundtrip response time.
I use jQuery to make working with XMLHttpRequest simple. I am using the JSONP variant, and that piece works - pulling AJAX requests from a different IP address or port is no problem in and of itself.
The idea I have is that when the page first loads, it fires off 2 getJSON calls. One to port 8001 and another to port 80. The same response handler is used in both calls.
The first call the response handler sets my "portToUse" variable and then proceeds with normal functionality.
This works when port 8001 is not blocked. If port 8001 is blocked, this works as well. However, there is an about 5 second delay before my response from port 80 comes back. This is not caused server side. I would like to eliminate this delay.
My theory is that even though getJSON is asynchronous, the browser only fires off one XMLHttpRequest at a time. It waits before the first one either returns or times out before sending the next one.
I am not sure if I am right. If I am, then is there a way to bypass this functionality and fire off both XMLHttpRequest at the same time? If I am wrong, do you have a suggestion as to what could be causing the delay in receiving my second response (from port 80 on my server)? Any and all other suggestions are welcome as well.
EDIT: This behavior only happens in Firefox 3 and Opera 9.63. IE7 and Chrome do not exhibit this delay.