[whatwg] Link.onload; defer on style, depends

On Tue, Mar 24, 2009 at 7:24 PM, Ian Hickson <ian at hixie.ch> wrote:
> On Sun, 15 Feb 2009, Boris Zbarsky wrote:
>> >
>> > So in this:
>> >
>> > ? ?<!DOCTYPE html>
>> > ? ?...
>> > ? ?<script>
>> > ? ? document.write('<link rel=stylesheet href=style>');
>> > ? ? document.write('<script>a();<\/script>');
>> > ? ? b();
>> > ? ?</script>
>> >
>> > ...is the script paused after the second document.write() call, before a()
>> > and b() execute?
>>
>> No. ?What's paused is execution of new scripts, not of existing ones. So in
>> this case, b() executes immediately, while a() executes after the stylesheet
>> loads.
>
> Woah, so this can affect the order of script execution?
>
> That seems very dangerous. What if b() depends on a()? I would be
> surprised if this didn't cause compatibility problems.

As Boris points out, it doesn't change the order of execution compared
to having the <link rel=stylesheet> block, which is what gecko used to
do. Not sure what other browsers do.

> On Sat, 14 Feb 2009, Garrett Smith wrote:
>> Boris:
>> > Garrett:
>> > >
>> > > What would make it easier? I'd really like to know how to design my
>> > > pages so that they are faster and more responsive.
>> >
>> > Well, one option is to stop worrying about micromanaging the load
>> > order and assume that speculative parsing will solve your problems....
>> > will it?
>>
>> Possibly. If the author could declare what a script depends on and let
>> the implementation determine what to load and when, would that be too
>> complicated?
>
> It seems like this is in general an issue that would be best left up to
> the browsers to optimise for, instead of having authors be able to
> micromange this (as Boris put it).
>
> In general, scripts shouldn't depend on style sheets anyway; if you are
> writing code where you want things to be fast, just avoid breaking that
> rule of thumb and then it will never matter.

It's unlikely that we'll ever get to a point when scripts won't depend
on stylesheets though. Until CSS is perfect we'll always have to have
scripts that create more advanced layouts than what CSS can produce,
and these scripts are likely going to depend on data not available
until all relevant stylesheets have loaded.

So basically I put this argument in the same group as "content
shouldn't depend on undefined behavior" ;)

In fact, I believe that google was the big problem when we tried not
blocking on pending stylesheets. Something about ads hosted on
websites where the scripts from google relied on style information.

All that said, I would love to not have to block scripts on pending
stylesheets. If all other browsers get away with it, I think we should
be able to as well.

/ Jonas

Received on Wednesday, 25 March 2009 17:06:31 UTC