defer scripts and execution order on browsers

HTML5.0 spec says this:

If the element has a src attribute, and the element has a defer attribute, and the element has been flagged as “parser-inserted”, and the element does not have an async attribute

The element must be added to the end of the list of scripts that will execute when the document has finished parsing associated with the Document of the parser that created the element.

The task that the networking task source places on the task queue once the fetching algorithm has completed must set the element’s “ready to be parser-executed” flag. The parser will handle executing the script.

So it does say it defers script execution until the associated Document is parsed, it also says it’s pushed into the list. So the order of the list should be as the script order is being parsed-inserted.

However, the second part kind of worries me. It basically says that it will only be marked for execution until the network task finsihed downloading the script. Then… “parser will handle executing the script”.

What I couldn’t find in the spec is the case covering script execution after document parsing. Does it keep executing scripts in the list order as they become “ready to be parser-executed”? Or will it wait until all scripts in the list are “ready to be parser executed” then execute them.

Spec (step 15): http://www.w3.org/TR/html5/scripting-1.html#script-processing-src-prepare

Leave a Comment