Open Bug 621553 Opened 12 years ago Updated 11 years ago

Implement HTML5 Specification Suggestion to Download Scripts Upon SRC attribute Assignment


(Core :: General, defect)

Not set





(Reporter: serverherder, Unassigned)




User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20101209 Fedora/3.6.13-1.fc13 Firefox/3.6.13
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20101209 Fedora/3.6.13-1.fc13 Firefox/3.6.13

The HTML5 specification makes a suggestion in running a script, step 12
"For performance reasons, user agents may start fetching the script as soon as the attribute is set, instead, in the hope that the element will be inserted into the document."

Currently only IE (4+) implement this behavior -- The test URL above loads the scripts in approximately 5 seconds, as opposed to Firefox loading them in 10. 

Were Firefox to implement this suggestion, both parallel loading dependencies and pre-fetching script elements for deferred execution would be rather simple to implement.  

Reproducible: Always

In FF <=3.6, workarounds exist that rely on FF's execution order preservation; however, this behavior contradicts the HTML5 specification and has been removed in FF 4.  This has lead to the  the `async=true` implementation. which reverts FF back to synchronous execution.  While this works, the specification only defines behavior for the async attribute on parser-inserted scripts.  Moreover, using async=true requires utilizing a global script queue, which can lead to the blocking current versions of Firefox are prone to.
Product: Firefox → Core
QA Contact: general → general
It's actually really hard to do this without leaking memory....
I can imagine.  Not sure if it helps (or is even related), but Internet Explorer aborts outstanding network connections if the JS variable is garbage collected -- A reference to the element must be  maintained while it is in-flight.  For example, this will abort in IE (sometimes) 
 var i=0; 
 while ( i++ <= 10 ) { 
   var script= document.createElement('script'); 
   script.onreadystatechange= function(){ document.body.appendChild(this); }
   script.src= "....";

A reference to each element must be maintained to prevent GC from occurring.   Would this make it easier to prevent leaks?
The script loader in Gecko holds a reference to the element being loaded.  So it wouldn't be able to get garbage collected.
You need to log in before you can comment on or make changes to this bug.