[whatwg] defer on style, depends
bzbarsky at MIT.EDU
Sun Feb 15 13:08:07 PST 2009
Ian Hickson wrote:
> On Fri, 13 Feb 2009, Boris Zbarsky wrote:
>> The current Gecko behavior is that any stylesheet load started by parsing a
>> <style> or <link> tag will increment a counter on the document (well, on a
>> per-document script loader object, to be more precise). Completion of the load
>> will decrement the counter. While the counter is nonzero, <script> execution
>> is blocked. When it goes back to 0, the first pending script (if any) is run.
>> If this increments the counter again, no more scripts are run until the count
>> goes to 0 again.
>> So it doesn't matter how the script is created/inserted, but the only
>> stylesheets that block scripts are ones that the parser knows about. So only
>> the ones present in the original source or added via document.write. If you
>> createElement a <link> and insert it into the DOM, it won't block script
>> execution. Also, <link> elements pointing to alternate style sheets don't
>> block script execution.
> So in this:
> <!DOCTYPE html>
> document.write('<link rel=stylesheet href=style>');
> ...is the script paused after the second document.write() call, before a()
> and b() execute?
No. What's paused is execution of new scripts, not of existing ones.
So in this case, b() executes immediately, while a() executes after the
Here's a simple testcase to demonstrate that:
var res = "";
document.write('<link rel=stylesheet href="data:text/css,">');
I realize that this does mean that the execution order of a() and b() is
different if the <link> is written out as above....
More information about the whatwg