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

Boris Zbarsky bzbarsky at MIT.EDU
Wed Mar 25 07:52:04 PDT 2009


Ian Hickson wrote:
> So testing this:
> 
>    http://software.hixie.ch/utilities/js/live-dom-viewer/saved/44
>    http://software.hixie.ch/utilities/js/live-dom-viewer/saved/45
> 
> (44 uses currentStyle, for IE/Opera, 45 uses getComputedStyle, for Opera/ 
> Firefox/Safari)
> 
> It seems Gecko is the only engine that blocks here.

That's quite odd.  The behavior this is showing in Safari, in 
particular, is the one described in 
<http://webkit.org/blog/66/the-fouc-problem/>, and last I'd heard that 
was causing compat issues and was going to be changed.  Specifically, 
see <https://bugzilla.mozilla.org/show_bug.cgi?id=84582#c16>.   Maybe it 
hasn't been changed after all?

> It would be interesting to hear from other browser vendors about their 
> opinions on this issue.

I would too.

>> 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?

Yes, just like document.write(<script src=...>) would, no?

> That seems very dangerous. What if b() depends on a()? I would be 
> surprised if this didn't cause compatibility problems.

For what it's worth, we shipped this behavior in Firefox 3.0 and I have 
yet to see a bug report about anything other than rare instances of 
flashes of unstyled content due to scripts in one frame forcing layout 
in another while stylesheets are still loading in the latter.

> On Sat, 14 Mar 2009, Greg Houston wrote:
>> On a side note, I can actually attach a functioning onload event to a
>> link element in Internet Explorer. Firefox, Safari, and Chrome ignore
>> my attempt, and Opera will fire the onload event but not update the
>> style of the page.
> 
> Since there are already implementations of this I've gone ahead and 
> defined it.

I have a question about this text.  It says that the load event is fired 
asynchronously; that's fine.  However, the page load event is fired 
synchronously on completion of network activity in some cases (at least 
in Gecko).  Which means that if no steps are taken to prevent it, if the 
last resource loading is a stylesheet the load event for the page will 
fire before the load event for the stylesheet.  It's not clear to me 
whether this is ok per the spec text.  Note that for image load events 
such steps to prevent are in fact taken (a pending image load event 
blocks the page onload from firing).

-Boris



More information about the whatwg mailing list