[whatwg] ProgressEvents for Images

Ian Hickson and I have been debating the merits of adding support for the
loadend event to images on https://bugs.webkit.org/show_bug.cgi?id=76102.
Dirk Schulze requested that the discussion be relocated here, since it's
about a feature and not the details of an implementation change.

Here's a recap, if you don't want to wade through the bug comments:

  Hans - You're saying that the [image] loadend event is useless?

  Ian - Yes.  It only saves typing a few characters, img.onloadend =
function () { }; vs:  img.onload = img.onerror = function () { };

  Hans - It's useful if you want your listener to run after all of the
load listeners have run, and code that you haven't written adds its own
load listeners.

  Ian - That seems like a rather obscure edge case, and you can work
around it using setTimeout() (in the load/error event handler) anyway.

Before carrying on, I should point out that the proposal to add loadstart,
progress, and loadend events to Image was modeled on XHR and based on the
ProgressEvent spec http:// www.w3.org/TR/progress-events/.  It may be that
supporting the complete set of ProgressEvents for images doesn't add
enough utility to be warranted.  We proposed supporting all of the
ProgressEvents (even loadend) for the sake of consistency.  And we're
aware of the CORS issues.

That said, here is the example I'd made, to demo the utility of a loadend

  function notMyShowImageFunction(image, url)
      image.onload = doSomethingAtLoadTime;
      image.src = url;

  image.onloadend = doThisAfterAllLoadListenersHaveRun;
  notMyShowImageFunction(image, "...");

The problem with using setTimeout() to schedule a listener to run after
all of image's load listeners has run is that you've got to guess how long
loading the image (or failing to load the image) and running its listeners
will take.  

If applications where multiple image load listeners are added by different
modules really are a rarity (I wouldn't know) then I'll be happy to
concede that loadend isn't needed.  If they are not, as I assume similar
XHR applications are not, then I don't think it's fair to characterize the
loadend event as useless.

- Hans

Received on Thursday, 23 February 2012 16:38:52 UTC