[whatwg] defer on style, depends
Ian Hickson
ian at hixie.ch
Mon Feb 9 00:23:37 PST 2009
On Sun, 8 Feb 2009, Jonas Sicking wrote:
> >>
> >> This will allow browsers to not block on those elements.
> >
> > Browsers are already allowed to not block on those elements.
>
> Well, Garrett is somewhat correct. For example in the following
> scenario:
>
> <link rel=stylesheet href="external.css">
> <script>
> doStuff();
> </script>
>
> In gecko, when we parse the <script> tag, we'll block until all external
> stylesheets have finished loading before we start executing the script.
> This is because the script might be getting .offsetLeft or calling
> .getComputedStyle or some such, which uses style data. We have found
> that some sites break if we just use whatever style data happens to have
> loaded at that point, rather than ensuring that all stylesheets have
> been parsed and applied.
Yes, external CSS can cause <script> elements to block on the CSS.
> However adding a 'defer' attribute to the style link seems like an odd
> fix as nothing is actually deferred. You very rarely actually want to
> defer stylesheet loading as you generally want to show content with
> stylesheets applied. Unstyled content tends to at best be ugly, at worst
> be totally nonsensical.
>
> A more logical fix would be to add an attribute to the <script> in
> question, indicating that the script can be executed without waiting for
> all stylesheets to load. Though that can be very painful to add to all
> scripts in the page. Possibly a page-wide attribute or API would better
> solve this problem. Though I'm not really a fan of either of those
> solutions either.
I'm not convinced either of these are really great solutions. I think it'd
be better just to have the script itself only block when it hits
CSS-dependent APIs (though I recognise that that is a much harder problem
in most rendering engines today).
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list