WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
Bug 76102
Add support for loadstart, progress, and loadend ProgressEvents to the IMG tag.
https://bugs.webkit.org/show_bug.cgi?id=76102
Summary
Add support for loadstart, progress, and loadend ProgressEvents to the IMG tag.
Hans Muller
Reported
2012-01-11 14:14:08 PST
Many applications that display large images, large numbers of images, or images that load slowly, would benefit from support for progress events. Displaying a progress indicator for work being done on the user's behalf is reassuring. Support for progress events would make it straightforward for applications to do this when images are being loaded. Currently some applications use XMLHttpRequest (XHR) to download image data while reporting progress. Doing so is somewhat complicated and can be inefficient. This is a request to add support for loadstart, progress, and loadend events to the IMG tag. The semantics of the events would be roughly the same as for XHR or the File API. ProgressEvents would be dispatched for loadstart, progress, abort, error, load, and loadend. We suggest promoting the type of the existing IMG load, error, and abort events from Event to ProgressEvent. ProgressEvents for cross-origin images should not reveal the actual resource size per
http://www.w3.org/TR/progress-events/#security-considerations
. This could be avoided by dispatching ProgressEvents with lengthComputable=false (and loaded=0, total=0) for cross-origin images. Alternatively we could dispatch a subclass of ProgressEvent with normalized total and loaded attributes. A normalized image ProgressEvent wouldn't expose the actual size of the resource being downloaded but it would still enable developers to observe relative progress. Normalization would set total to a constant like 1000, and loaded to a relatively correct value.
Attachments
Add attachment
proposed patch, testcase, etc.
Ian 'Hixie' Hickson
Comment 1
2012-02-06 15:17:26 PST
I'd recommend not sending any events at all for non-CORS-aware cross-domain images.
Hans Muller
Comment 2
2012-02-06 16:44:52 PST
(In reply to
comment #1
)
> I'd recommend not sending any events at all for non-CORS-aware cross-domain images.
I assume that you don't mean that we should no longer dispatch the existing load/error/abort events for non-CORS-aware cross-domain images? And if we're going to carry on dispatching those events, dispatching the companion loadend event wouldn't expose any new information.
Ian 'Hixie' Hickson
Comment 3
2012-02-13 12:45:33 PST
I would only fire 'load' and 'error'. I would avoid firing the other events because it either exposes information, in which case it's a security problem, or it exposes no information, in which case it's a useless API that will mislead authors.
Hans Muller
Comment 4
2012-02-13 12:50:58 PST
(In reply to
comment #3
)
> I would only fire 'load' and 'error'. > > I would avoid firing the other events because it either exposes information, in which case it's a security problem, or it exposes no information, in which case it's a useless API that will mislead authors.
The loadend event, which is what I assume you're characterizing as "useless", enables doing work after either the load or error listeners have run. That seems useful on the face of it, and I assume that's why the ProgressEvent spec includes loadend.
Ian 'Hixie' Hickson
Comment 5
2012-02-13 12:59:51 PST
"loadend" is basically uninteresting. It's just a shortcut to calling the same function from both the 'load' and 'error' handlers. It literally saves only a few characters: img.onloadend = function () { }; ...vs: img.onload = img.onerror = function () { };
Hans Muller
Comment 6
2012-02-13 15:32:32 PST
(In reply to
comment #5
) If only one image error/load listener is used and you're defining it yourself then I agree that there's definitely not much value in having a loadend event. If other code contributes image listeners, then there is value. For example: function notMyShowImageFunction(image, url) { image.onload = doSomethingAtLoadTime; image.src = url; } image.onloadend = doThisAfterAllLoadListenersHaveRun; notMyShowImageFunction(image, "...");
Ian 'Hixie' Hickson
Comment 7
2012-02-15 21:21:30 PST
That seems like a rather obscure edge case, and you can work around it using setTimeout() (in the load/error event handler) anyway.
Dirk Schulze
Comment 8
2012-02-15 21:31:04 PST
(In reply to
comment #7
)
> That seems like a rather obscure edge case, and you can work around it using setTimeout() (in the load/error event handler) anyway.
Wouldn't it be better to move this discussion to #whatwg mailing list? I'd like to use bug reports for discussions about implementation details and not for general discussions about features.
Ian 'Hixie' Hickson
Comment 9
2013-01-03 16:52:40 PST
Spec updated.
Rudin
Comment 10
2013-05-21 03:50:25 PDT
Any news on this? Image progress events were added to the HTML spec:
http://www.whatwg.org/specs/web-apps/current-work/#the-img-element
Want this, need this. Been able to do this in Flash like, back in '99.. ;-(
Yonatan
Comment 11
2014-01-22 06:53:31 PST
Does anyone know if this bug is scheduled to be fixed soon?
Martin P.
Comment 12
2015-02-15 07:49:26 PST
+1. I'd like to see that implemented too. It will especially by useful for the new <picture> tag and the srcset-attribute for <img> to know when another resource (eg. on orientation change) is being loaded...
Simon Pieters (:zcorpan)
Comment 13
2015-04-30 04:40:37 PDT
(In reply to
comment #12
)
> +1. > > I'd like to see that implemented too. > > It will especially by useful for the new <picture> tag and the > srcset-attribute for <img> to know when another resource (eg. on orientation > change) is being loaded...
That is not part of the spec currently. What's the use case? (Please file a new spec bug
https://github.com/ResponsiveImagesCG/picture-element/issues
)
Martin P.
Comment 14
2015-05-01 01:29:31 PDT
(In reply to
comment #13
)
> (In reply to
comment #12
) > > +1. > > > > I'd like to see that implemented too. > > > > It will especially by useful for the new <picture> tag and the > > srcset-attribute for <img> to know when another resource (eg. on orientation > > change) is being loaded... > > That is not part of the spec currently. What's the use case? (Please file a > new spec bug
https://github.com/ResponsiveImagesCG/picture-element/issues
)
Yes it is part of the WHATWG HTML Living Standard specs. Search for "loadstart" in
http://www.whatwg.org/specs/web-apps/current-work/#the-img-element
. I think there is no other way of detecting that a (specific) image starts being loaded by the browser. That can be useful for displaying loading indications. I find it especially interesting when using the <picture> element. By using <picture>, the src of an <img> tag can change after the page finished loading, eg. on a viewport resize or an orientation change. That results in a blank/white image for the time the images is actually being loaded - with a loadstart event you could let the user know about the loading, eg. by showing a loading indicator.
Simon Pieters (:zcorpan)
Comment 15
2015-05-04 04:22:52 PDT
(In reply to
comment #14
)
> Yes it is part of the WHATWG HTML Living Standard specs. Search for > "loadstart" in >
http://www.whatwg.org/specs/web-apps/current-work/#the-img-element
.
That algorithm is not run "eg. on orientation change". Then this algorithm is run instead
https://html.spec.whatwg.org/multipage/embedded-content.html#img-environment-changes
and it does not fire loadstart/progress.
> I think there is no other way of detecting that a (specific) image starts > being loaded by the browser. That can be useful for displaying loading > indications.
Why would you want a loading indicator for environment changes instead of just swapping the image when it is loaded?
> I find it especially interesting when using the <picture> element. By using > <picture>, the src of an <img> tag can change after the page finished > loading, eg. on a viewport resize or an orientation change. That results in > a blank/white image for the time the images is actually being loaded - with > a loadstart event you could let the user know about the loading, eg. by > showing a loading indicator.
No, the old image would keep showing until the new one is completely loaded, per spec.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug