W3C home > Mailing lists > Public > public-html@w3.org > October 2009

Re: [HTML5] DOMContentLoaded fires before CSS resources loaded?

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Sun, 04 Oct 2009 23:02:38 -0400
Message-ID: <4AC961CE.7020708@mit.edu>
To: Ian Hickson <ian@hixie.ch>
CC: "public-html@w3.org" <public-html@w3.org>
Ian Hickson wrote:
> For _any_ <script> element, internal or external, parser-inserted and 
> dynamically inserted, once the script has loaded and is about to be 
> executed, if there are "pending style sheets" (defined below), then 
> act as if the script had not yet finished loading, until such time as any 
> "pending style sheets" have loaded.
> 
> "Pending style sheets" are those that were referenced by <link> or <style> 
> elements inserted by the parser, or Link: HTTP headers, and that were 
> inserted into the document (by the parser) _before_ the relevant <script> 
> was inserted into the document (by the parser or script).

Assuming "have loaded" includes loading all @import descendants, I 
believe this would more or less match Gecko's current behavior, yes, 
with two differences I can think of:

1) Stylesheets are only considered pending if they were in the 
then-selected stylesheet set when they were inserted into the document. 
  That is, alternate stylesheets don't block anything from happening in 
Gecko right now.

2) Gecko does not impose the "before the relevant <script>" condition. 
If a stylesheet is pending and you insert a <script> dynamically (off a 
timeout say), and then another stylesheet load starts from the parsr 
(which didn't block on the dynamically inserted script, of course) 
before the previous one completes, the <script>s execution will wait on 
the end of that second stylesheet load as well.

I'm not 100% wedded to this behavior, though I do happen to think it 
makes sense (modulo caveat 2 above possibly).  But I'm biased, 
obviously; if I thought it didn't make sense I would have implemented it 
differently.  If there are obvious issues with it, or just obvious 
improvements to be made, I'd be quite happy to know what they are.  I 
can see how the "inserted before the relevant <script>" condition might 
make more sense, but it involves a lot more bookkeeping (in particular 
keeping track of which stylesheets are loading, not just whether any are 
loading at all), which is sort of why we didn't implement it that way 
(or rather why the idea hadn't even been considered).

> It also sounds like you want the parser to stop blocking everything while 
> waiting for an external script to finish loading.

Right; on this I feel much more strongly than on the precise behavior of 
stylesheet/script interaction...  Blocking processing of data in the 
parser is a must.  I'm not sure blocking processing of everything else 
is reasonable.

-Boris
Received on Monday, 5 October 2009 03:03:59 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:16:49 GMT