[whatwg] defer on style, depends

Ian Hickson wrote:
> By the way, the spec doesn't yet require the blocking behavior. I couldn't 
> work out how to do it. Could you elaborate on when exactly in the process 
> the style sheet is waited on? Does it happen for all scripts? For example, 
> if a script inserts a style sheet and then a script, does that script wait 
> for the style sheet to load?

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.

Let me know if you want more details about any part of this.

> On Thu, 12 Feb 2009, Boris Zbarsky wrote:
>> I'm proposing flagging scripts that don't depend on stylesheets
> 
> It seems like it is likely that such a feature would end up used before it 
> works, with the result being that implementors get forced to not support 
> it (a typical "race to the bottom" seen in browser implementation).

Yeah, I did mention that as an explicit worry...

-Boris

Received on Friday, 13 February 2009 06:36:04 UTC