Question

I've 2 js functions, request() and response(). Request injects a dynamic script tag to DOM, loading some "script" from server. The script that comes from server is set to call response().

Now if I make 5 calls one after the other immediately, and if first one is still waiting, the next 4 calls are still made, the response comes back (I saw that from Firebug), but response() is not called until the first one returns.
This is happening only in Firefox. :(

Why is this not making the function call ?

PS :

  1. if first request is being delayed, I don't care about its results, I want the last one to be loaded and calling response without delays..
  2. I tried $.ajax with dataType set to 'jsonp', pure javascript style insertion of script tags and $.getScript. Nothing seems to be working well with FF :(

Edit : For those who requested code samples :

function request(){

    var URL = 'http://xxx.xxx.xxx.xxx/cgi-bin/response.php?callback=?';
    callHandle = $.getScript(URL);

}

function response(data){

      alert(data);
}

the request function calls the server's php script, which has following code :

$data = $_GET['callback']; //using just to identify request uniquely.
sleep(rand(1,10));
echo "response(".$data.")";

Now if first request takes 10 seconds, and second request takes 2 seconds, the response should be called back for the second request. But it is getting the response, but instead of alerting, it is waiting for first request to complete in firefox. Why is this so ?

Was it helpful?

Solution

I've seen the same thing: Firefox handling the return responses (javascript inclusions done with document.createElement('script') and append them to the Head-Node) in the order in which script elements were appended to the document. From a programmer viewpoint this simplifies programming. However, I think you should treat this as an implementation detail from this browser (version), not a guarantee. Google chrome executes the included scripts in any (unexpected) order.

This behavior is already called "Old firefox behavior" when looking to Firefox 4 and HTML5 compliance ( http://hsivonen.iki.fi/script-execution/ )

The Old firefox behavior

Script-inserted external non-async, non-defer scripts executed in the order they were inserted into the document.

Have you tried inserting your scripts with document.write?

OTHER TIPS

Unless this is for educational reasons, I suggest using a library which deals specificly with these browser idiosyncrasies. e.g: http://code.google.com/p/controljs/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top