Firefox doesn't do “asynchronous” load on dynamic script injection?

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 ?

Answers


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?


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/


Need Your Help

Are there any nearest neighbor data structures using a user provided hint?

c++ algorithm data-structures computational-geometry nearest-neighbor

I am looking for a data structure holding vectors in R^n which could perform nearest neighbor queries using a user provided hint as to which vector is likely to be close to the query. For example:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.