W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2009

[whatwg] defer on style, depends

From: Ian Hickson <ian@hixie.ch>
Date: Mon, 9 Feb 2009 10:26:31 +0000 (UTC)
Message-ID: <Pine.LNX.4.62.0902091022330.952@hixie.dreamhostps.com>
On Mon, 9 Feb 2009, Garrett Smith wrote:
> 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.
> 
> But they do.
> 
> If a script occurs after a link, the script expects updated style 
> information. That is why browsers do block on scripts.

They block on scripts, yes. (Not on style.)

See my reply to Jonas for further discussion of this matter.


> >> It would be more complete to have a depends attribute on script and 
> >> style.
> >>
> >> <script depends="a b c"></script>
> >>
> >> Where the depends is id-list [CS], space separated values of element 
> >> IDs.
> >
> > Why can't you just put the <script> element below the elements whose 
> > IDs you would have listed?
> 
> An associated script might need that stylesheet to be loaded before it 
> runs. The depends attribute would guarantee that the stylesheet had 
> loaded. The order should not change because the script is an inline 
> scripts vs an external resource.

It seems pretty simple to me; if you want the style to be loaded when the 
script runs, put the style first. If you don't, put the script first and 
defer it (or mark it async). Why should this not be enough?


> The "depends=" attribute allows the script to declare that it needs 
> style information first. This would be a much better design, and could 
> probably be implemented by the browser with some nice event-driven code. 
> Unfortunately, implementations that encounter <link defer 
> type="text/css"...>, followed by a script with no "depends" would still 
> have to block on that stylesheet because that is what they do today.
> 
> The script could declare itself as "independent".
> 
> That would result in links not blocking.
> 
> To allow the stylesheet to load after all content loads, the stylesheet 
> could declare defer:
> 
> <link defer src="deferred-all-min.css" type="text/css" rel="stylesheet" 
> id="lateBoundCSS">
> 
> To fulfill a requirement of having loaded of the stylesheet before the 
> script runs, that script could declare depends to declare that it needs 
> style information before loading.
> 
> <script defer depends="lateBoundCSS" src="app-all-min.js"></script>

This seems like an inordinate amount of complexity for something that can 
just work already.


> >> It would also be useful to have a way to dynamically load scripts, 
> >> other than createElement("script").
> >
> > This seems like a request for the ECMAScript group.
> 
> Maybe. I would probably not be able to use it before I retire.

We should not design specifications around the characteristics of the 
committees. If you have a problem with the ECMAScript group, I urge you to 
bring it to their attention. This forum is inappropriate for such 
discussion.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Monday, 9 February 2009 02:26:31 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:09 UTC