[whatwg] DOMContentLoaded and stylesheets

Boris Zbarsky bzbarsky at MIT.EDU
Thu Feb 11 13:00:42 PST 2010

On 2/11/10 9:07 AM, Mathias Schäfer wrote:
> But if there’s a script after the stylesheet, DOMContentLoaded always
> fires after the stylesheet has been loaded. The explanation I’ve found
> is that the parser waits for the stylesheet to load before subsequent
> scripts are executed.


>> step 8 the cases that talk about "a style sheet blocking scripts"
>> specify this.
> Thanks for the hint. AFAICS only the third case talks about “a style
> sheet blocking scripts”. But this case only deals with “parser-inserted”
> inline scripts.

Ah, indeed.  For non-inline scripts the relevant part is step 2 under 
the "If the load was successful" part in 

> The question is: Is a normal external script “parser-inserted” or not?


> I assume the flag to be false, since that’s the default value and I
> found “parser-inserted” to be true for XML parsing only
> (#parsing-xhtml-documents). Correct?

No.  The HTML parser state machine sets that flag in various cases.  For 
under 'A start tag whose tag name is "script"'.

> <link rel="stylesheet" href="...">
> <script src="..."></script>
> ... and I would like to step through the parsing algorithm. This is my
> understanding so far:
> 4. We’ve reached step 8 which you’ve mentioned above. I assume the
> fourth case is true (“If the element has a src attribute”), since the
> script is not “parser-inserted”.

The script is in fact parser-inserted, but you still land in the fourth 
case, I think.

> 9. “Pause until either any applicable style sheets have been fetched and
> applied, or the user agent has timed out and decided to not wait for
> those style sheets.” (step 2)
> -->  I guess *this* is where the waiting happens, right?


> That means, inline script execution should also wait for stylesheets to
> load. Am I right in this reading?



More information about the whatwg mailing list