W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2012

[whatwg] should we add beforeload/afterload events to the web platform?

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Tue, 10 Jan 2012 11:43:20 -0500
Message-ID: <4F0C6AA8.2000506@mit.edu>
On 1/10/12 2:22 AM, Henri Sivonen wrote:
> I'm worried about the interaction with speculative loading. Right now,
> Gecko is more aggressive than WebKit about speculative loading.

Actually, I just checked and WebKit simply fires the "beforeload" event 
way after it actually starts the load in speculative load situations. 
Consider this testcase:

<!doctype html>
<script>
   var start = new Date;
   var log = "";
   document.addEventListener("beforeload", function(e) {
     log += "Starting load of " + e.target.id + ": " + (new Date - 
start) + "\n";
   }, true);
   window.onload = function() {
     log += "Finished page load: " + (new Date - start) + "\n";
     alert(log);
   }
</script>
<script id="one" 
src="http://landfill.mozilla.org/ryl/slowResponse.cgi?time=4"
         onload="log += 'Finished load of one: ' + (new Date - start) + 
'\n'"></script>
<script id="two" 
src="http://landfill.mozilla.org/ryl/slowResponse.cgi?time=5"
         onload="log += 'Finished load of two: ' + (new Date - start) + 
'\n'"></script>

The slowResponse.cgi script takes N seconds to respond where N is passed 
in the "time" parameter.

When I load this testcase in either Chrome or Safari, I see the "load of 
one" start at about 1ms into the timeline an finish about 4s into the 
timeline.  I see the "load of two" start about 4s into the timeline and 
finish about 5s into the timeline.  Since the "load of two" actually 
takes at least 5s from when it starts, that means that the load really 
started about 4s before the "beforeload" event fired.

So in WebKit this event is only good for preventing _processing_ of the 
data in the page (e.g. preventing the script from executing when the 
target is a <script>) but not much use for preventing loads, even if 
some people seem to think that it is.

> I don't want to make Gecko less aggressive about speculative loading in
> order to fire beforeload exactly at the points where WebKit fires
> them.

The good news is that per above we really wouldn't have to; we'd just 
fire it as late as we feel like.  ;)

-Boris
Received on Tuesday, 10 January 2012 08:43:20 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:10 UTC