I'm trying to implement a iGoogle like dashboard interface using widgets that get their content from other sites using JSONP calls.
The problem is that if the first widget that calls the "$.ajax" takes 8 seconds to get the content back, it seems that the callbacks of the other widgets will only be called after the callback of the first widget gets executed. For the user experience, it would be better if the widgets could be displayed as soon as they get the content back from the remote sites, and not wait for those that were scheduled before to complete.
Is there a way I can do that?
EDIT : I use jquery 1.4.1.
I tested on Chrome and the behaviour seems to be different than on Firefox.
Here is a script that I've made up to try to get what happens :
function showTime(add) { console.log(getTime() + ': ' + add); }
function getNow() { return new Date().getTime(); }
initialTime = getNow();
function getTime() { return getNow() - initialTime; }
function display(data) { showTime('received a response'); }
showTime("Launched a request");
jQuery.getJSON("http://localhost:51223/WaitXSeconds/3?callback=?", display);
showTime("Launched a request");
jQuery.getJSON("http://localhost:51223/WaitXSeconds/4?callback=?", display);
showTime("Launched a request");
jQuery.getJSON("http://localhost:63372/WaitXSeconds/9?callback=?", display);
showTime("Launched a request");
jQuery.getJSON("http://services.digg.com/stories/top?appkey=http%3A%2F%2Fmashup.com&type=javascript&callback=?", display);
showTime("Launched a request");
jQuery.getJSON("http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US&callback=?", display);
The first three calls are just fake calls that wait the specified number of seconds. Note that I use two different servers implementing this method.
Here is the result in the console on Firefox 3.6.2 :
0: Launched a request
3: Launched a request
6: Launched a request
11: Launched a request
14: Launched a request
3027: received a response
7096: received a response
9034: received a response
9037: received a response
9039: received a response
.. and here is the result in Chrome 4.1.249.1036 (41514) :
1: Launched a request
2: Launched a request
3: Launched a request
4: Launched a request
5: Launched a request
165: received a response
642: received a response
3145: received a response
7587: received a response
9157: received a response
It seems that in Firefox, the two requests to the two public APIs get called at the end, after all the other calls succeed.
Chrome, on the other hand, manages to execute the callback as soon as it receives the response.
On both browsers, when the request happen on the same server, they are not done in parallel. They are scheduled one after the other. But I guess this is a reasonable behaviour.
Can anybody explain Firefox's behaviour or has any hack to go around this?