Responsive images - hacks won't cut it
TL;DR
Responsive images are important for mobile performance. Hacks may solve the problem, but they come with their own performance penalty. Browser vendors must step up to create a standard, supported method.What we have
There have been several techniques published lately that enable responsive images using various hacks:
- Harry Roberts suggested to use background images & media queries to deliver larger images to desktop browsers
- Keith Clark suggested to use JS at the document head to plant cookies that will then send the device dimensions to the server with every image request. The server can then serve different image dimensions on the same image URL
- Yet another approach is that of the filament group which is based on dynamically modifying the base tag according to device dimensions
Not good enough
The reason we need responsive images in the first place is to avoid downloading excessively large images and avoid the performance penalty that such excessive download incurs.
All current techniques avoid some of this performance penalty, but come with new performance issues. Using the same URL for images in different dimensions means that the images can't be cached by intermediary cache servers. Using only/mainly background images means that images download won't start until the CSS was downloaded and parsed. It also means that the CSS that contains content-related image URLs cannot be long term cacheable. Dynamically modifying the base tag is generally frowned upon by browser vendors since it can mess up the preload scanner, that loads external resources before all CSS and JS were downloaded and run.
All in all, since techniques that modify the URL prevent the preload scanner from working properly, and techniques that don't modify the URL prevent caching, I don't see how a responsive images hack can avoid a performance penalty of its own, which kinda misses the point.
What we need
We need browser vendors to step up and propose (i.e. implement ☺) a standard method to do this. A standard method that will be supported by the preload scanner, and therefore, won't delay image download and won't have a performance penalty.
I have made a proposal a couple of months ago for such a method, in response to Nicolas Gallagher's and Robert Nyman's proposals, but basically any method that will keep the URL maintenance burden in the HTML, keep both CSS & images cacheable, and will have no performance penalty will be welcome.
Thoughts?
3 comments
Gulrez — Thu, 04 Apr 2013 14:38:03 GMT
Thanx for help.....
Gulrez — Thu, 04 Apr 2013 14:38:39 GMT
ok
by
Gulrez — Thu, 04 Apr 2013 14:39:22 GMT
great