W3C home > Mailing lists > Public > public-web-perf@w3.org > April 2013

Re: <img src="..." defer>

From: James Simonsen <simonjam@google.com>
Date: Mon, 15 Apr 2013 17:44:04 -0700
Message-ID: <CAPVJQi=YpY8RNa9rzCgEaE-rP4LmWF90=JZLWufCxEVq9KHyTA@mail.gmail.com>
To: Jake Archibald <jakearchibald@google.com>
Cc: public-web-perf <public-web-perf@w3.org>
On Sun, Apr 14, 2013 at 10:52 AM, Jake Archibald
<jakearchibald@google.com>wrote:

> # "defer" behaviour:
>
> Images with 'defer' MUST NOT download while they aren't in a document, or
> their calculated 'display' style property is 'none'.
>
> The download state of images with 'defer' MUST NOT delay the 'load' event
> of the window.
>
> Images with 'defer' MAY download once they are in the document, and their
> calculated 'display' style property is not 'none'.
>
> Images with 'defer' MUST download once they are in the document, and their
> calculated 'display' style property is not 'none', and any part of the
> image would be visible within the viewport. If visibility within the
> viewport is uncertain (due to element size determined by image dimensions),
> the image MUST download.
>

These seem a bit onerous. I think the intent is reasonable, but we should
back off on the wording.

For instance, you don't want the browser to constantly recompute style for
every little change just so that it can decide whether or not to start
fetching a deferred image.

Likewise, spec'ing "visible within the viewport" is dangerous with modern
browser rendering architectures. Visibility is often determined by a
different thread or process entirely for the sake of smooth scrolling. I
think it'd be better to just say deferred images should be fetched when
convenient for the browser. We know we should focus on getting the onscreen
ones first. :)

I also don't think it's worth spec'ing the display:none criteria. If the
image is deferred, the browser now has the option of not loading it at all.
This was never a choice before. So, if now we don't _need_ to load an
image, we can try to figure out whether or not we _should_ load it. For
instance, if we can decide a display:none image would only become visible
on a phone's viewport, and we're on desktop, we can skip it. Or if we're
not sure how it would become visible, and the network is idle and cheap, we
can speculatively load it anyway. Even if we guess wrong and skip something
that'll be needed, we'll still fetch it when it comes into view, making it
no worse than "scrolled into view" situation.

A developer can make this easier for us by removing the defer attribute
when they decide it's needed. This should force us to fetch it.

Another important thing to keep in mind is that older browsers will fall
back to their default behavior, which is to ignore the new attribute and
fetch everything and block the load event. I think that's fine, because it
fails in a way that will still work correctly, if slower.

James
Received on Tuesday, 16 April 2013 00:44:31 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:04:35 UTC