- From: Ian Hickson <ian@hixie.ch>
- Date: Tue, 28 Apr 2009 06:50:37 +0000 (UTC)
On Mon, 27 Apr 2009, Boris Zbarsky wrote: > Ian Hickson wrote: > > The spec requires the page 'load' event to be fired asynchronously. > > (There's no black-box way to distinguish this from the case of waiting > > for the other 'load' events to have fired, as far as I can tell.) > > Phrased that way, yes. But maybe I wasn't clear on the exact behavior > Gecko has here. For image load events, not only does the async event > prevent the page load from firing until after it has fired, but it also > prevents _checking_ whether the page load should fire until after it has > fired. So if the image load event has a listener that starts new > network requests, the page load would not fire until after those > requests complete. In your proposed model above, whether it does or not > depends on the precise order in which the image's async load event races > with other network access. If it fires before all other network access > is complete (and therefore before your proposed async page load event > has been posted), the page load event will wait for the load started > from the onload handler. If not, then it won't. > > There are pros and cons to both setups, I guess; the race above is no > worse than a network request whose completion would trigger onload > racing against a timeout that starts a network request... On Mon, 27 Apr 2009, Boris Zbarsky wrote: > > Or did I misunderstand and by "fired asynchronously" you mean > "asynchronously check again whether all network activity is done"? (I > expect not, but just checking.) As far as I can tell, as specced, there isn't a race condition (other than the inherent network race condition). http://www.whatwg.org/specs/web-apps/current-work/#delay-the-load-event In this case: <body onload="2"> <img onload="1; image = new Image(); image.src = 'test'; image.onload = 3"> The main 'load' event is queued as soon as there is nothing left that depends on it -- which happens as soon as the <img> load event was queued up, but before it runs. So the handlers run in the order given (1, 2, 3). -- Ian Hickson U+1047E )\._.,--....,'``. fL http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,. Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
Received on Monday, 27 April 2009 23:50:37 UTC