[whatwg] defer on style, depends

Jonas Sicking jonas at sicking.cc
Sun Feb 8 23:26:08 PST 2009

On Sun, Feb 8, 2009 at 9:20 PM, Ian Hickson <ian at hixie.ch> wrote:
> On Sun, 8 Feb 2009, Garrett Smith wrote:
>> Sometimes a document's resources are not needed all at first. For
>> example, a script that is not needed until after the document is parsed
>> can be given the defer attribute (for browsers that support defer).
>> External css can also be a blocking download. Scripts have defer
>> attribute, but style and link do not.
>> The proposal is to add to defer to style, and link.
>> 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">

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.

I think at least some other browsers behave similarly.

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.

/ Jonas

More information about the whatwg mailing list