[whatwg] Detached elements and delaying the load event

Andrew Oakley andrew at ado.is-a-geek.net
Thu Jan 26 03:05:05 PST 2012


On 01/25/12 23:06, Ian Hickson wrote:
> On Tue, 6 Sep 2011, Andrew Oakley wrote:
>>
>> I'm going to use the <img> element as an example here, but the same 
>> thing applies to other elements such as <iframe>, <video>, <audio>.
>>
>> I'm going to assume that the user agent "obtains the images 
>> immediately", given that seems to be what most browsers do.
>>
>> If an img element is created and given a src attribute (but not 
>> necessarily attached to the tree) then, according to HTML5, we need to 
>> "update the image data" and therefore delay the load event.  I guess 
>> this means we should lock the image element in a similar fashion to 
>> XMLHttpRequest objects, otherwise the image could be garbage collected 
>> before it has been loaded and therefore block the load event 
>> indefinitely.
>>
>> Firefox, Opera, Chrome and Safari do seem to implement this behaviour, 
>> IE does not.
>>
>> I would prefer not to implement this and just say "detached elements do 
>> not delay the load event", but I'm not sure if that will always work.
>>
>> Can we please get a clarification in HTML5, either to say that these 
>> detached objects must not be garbage collected while they are delaying 
>> the load event, or to say that they do not delay the load event.
> 
> Done for <img>.

OK, so we don't GC the <img> while it is loading.

> <video> and <audio> already had requirements to this effect.

OK, that looks similar.

> <iframe> outside a document doesn't initiate a load, so it's case is 
> different.

I'm not sure it is - we can create an <iframe> in the document then
remove it before it loads.  Most browsers seem to give up on loading the
contents of the iframe if you do this (IE continues to delay the load
event until it has loaded the iframe).

As far as I can tell HTML5 says that you shouldn't do anything when an
iframe is removed from a document (and therefore the frame should
continue to load and delay the load event, assuming it isn't GC'd).

I think we should be consistent here - if we continue to delay the load
events for <img>, <video> and <audio> after they have been removed from
the tree then the same should be true for <iframe>.

-- 
Andrew Oakley



More information about the whatwg mailing list