This is silly and makes things way more complicated than they need to be.
We have HTML tags, to which we can apply attributes directly via blah=blah syntax
Or we can add attributes by making a style attribute, and using css syntax inside of it.
Or we can have a space separated list of class names, and have attributes applied to an element externally by a CSS stylesheet.
Or we can have an ID, and apply attributes using javascript.
We can apply attributes with http headers, and the browser can negotiate the resource with http accepts and quality parameters.
We have video, audio, and object tags that can all have child elements.
We have query parameters and fragment selectors, and path parameters, and post parameters and accept parameters for negotiating and selecting content from a server. (Designed to include ampersands which have to be entity encoded when used in HTML!)
We have all these sophisticated overlapping complicated mechanisms for attaching attributes to elements in a webpage. We have huge pieces of software for parsing through this poorly thought through mess.
But no, not a single one of these is good enough for this problem. LET'S INVENT A NEW SYNTAX AND ADD TO THE HEAP OF IDIOCY.
From an implementation point of view, putting everything in a single attribute is way simpler; the design of <video> is quite problematic. The reason is that with a single attribute everything can be processed atomically. With a design based on multiple elements things can happen between elements being processed, creating many more edge cases.
Although in general things that make authoring easier are preferred, designs that are easy to implement in a bug-free way are generally preferred over designs that are complex and likely to lead to interoperability issues. After all, having to fight implementation differences is a rather common complaint about the web platform.
It also hasn't been clearly demonstrated that multiple elements are easier to work with. They are more familiar, but significantly more verbose. I don't know how that plays out in practice.
The only problem with the <picture> element is how to address backwards compatibility? The srcset attribute is backwards compatible because old browsers will just ignore srcset and use the src, but old browsers will ignore the <picture> element completely -- how do you get something that works for older browsers but also works for new browsers as well?
This really feels like the wrong approach to me - like this will lead to "best viewed with iPhone 5" pages.
Whilst there will be ways to automate the setting of such img srcset attributes based on the device (eg the PHP method mentioned that relies on a cookie) this sort of tailoring for specific device [characteristics] seems wrong somehow.
IMO this would be better handled by devices declaring their preferred viewport and/or pixel density just as they declare language preferences now, ie browser headers. Then the server can be set to send different images based on the header values and we don't have to worry about having a massive "srcset" attribute on each image tailoring to 500 different device variants. A server config would specify what viewport ranges to use and tell the server how to modify the images sent (or modify the path, or modify the location - eg switch an image with a folder called image.jpg and have filename tagged images for the different variants handled).
Perhaps this seems hacky too ...
In any case the SRCSET attribute proposal here looks short-sighted and hackish to me.
Yeah, the srcset for every device type on every single image seems excessive. I was hoping we could take advantage of file naming conventions and define a way for user agents to request 'filename' + 'variant key' + 'filename extension' instead of the 'filename.extension' file in the src attribute when it wants non-1x images, where 'variant key' is something like "_2x" added to the filename for 2x images. Then you could just flag img tags as having 2x available boolean. I don't think whatwg likes the idea of file names as metadata, though.
Or, here's just a crazy out there thought. What if we save our images in high res progressive format, and program the browsers to stop downloading the images as soon as they've acquired enough resolution? Caching can be done with http range requests. Older user agents just end up downloading larger images than they wanted. Javascript and server script can use the JPEGtran library to retrieve lossless low res versions of jpeg images. Similar things could be done with png. No modifications to any standards need to take place.
It takes the approach of setting a cookie when the page first loads with the viewport size, determined through media queries. Every request to the server then includes this cookie.
When an img is requested (as an <img> tag or through CSS background-image) the cookie is read to determine the viewport size of the client. The PHP script then serves up the most appropriate image size to the client.
The only thing you really need to do is add the .htaccess rule (to intercept image requests and route them through the PHP script), the php script itself and the highest resolution you need for each image. The script takes care of scaling down the image for smaller screens, caching them for later use.
I like the way this requires nothing on the client side, other than a cookie being set. All the heavy lifting is done on the server.
The above example is exactly the same information as in this link. However it is expressed in one place and thus is far simpler. The only reason to do this per image would be if you different naming conventions for individual images.. which would just be silly.
You could then have a nosrcset attribute which you can add to images which do not have high-res versions. This would save an http request.
Better than this specification hassle is this solution:
The browser should send the density of the screen in ppi (calculated by the screen resolution and the screen information provided by the OS) together with all the other standard stuff like OS, screen resolution, etc.
With this information the server can decide which images to send.
Screen PPI (in physical pixels per physical inch) is not the relevant consideration - device pixels per CSS pixel being something other than 1 is the case you care about. And the browser needs to know the intended resolution of the image so it can tell whether to downscale it.
Web servers shouldn't need to rely on any other information than the URL in order to serve the right content. This keeps the simple use cases simple, as the URL directly translates to a file on the server. Otherwise every web werver in the world would need some special new logic for choosing different files.
I agree that the syntax isn't great, and a corresponding set of CSS rules would be welcome, but this does solve a problem.
What I'd love to see is something similar for bandwidth sets, so lower bandwidth connections can be sent lower quality images. And then for both features to be made available for video tags.
I believe this should be moved to the stylesheet. We already have ways to determine media/viewport/device/orientation etc so adding different imgs would be a no brainer.
That would mean the browser couldn't start downloading any image before it had downloaded and parsed the stylesheet. Or that it would download all images and the entire point of saving bandwidth is lost.
There must be at least one height / width / pixel density descriptor for each url, so if you see a comma before the url ends, you know it must be part of the url.
When I saw the last line in the doc linked above, I realized that <img srcset=""> is probably optimized for adding one (1) "retina" image for iPhones and other high-DPI devices.
I don't care if the syntax is a bit unsightly. Let's just get this into shipping browsers as soon as possible. It's a major requirement for responsive design and this has good fallback behaviour. We can all just stick to 'mobile first' design and a .js polyfill shouldn't be hard.
Responsive images are obviously needed but this syntax is noisy and confusing. Adding info after the file extension would make it too easy to overlook.
[+] [-] ZenPsycho|14 years ago|reply
We have HTML tags, to which we can apply attributes directly via blah=blah syntax
Or we can add attributes by making a style attribute, and using css syntax inside of it.
Or we can have a space separated list of class names, and have attributes applied to an element externally by a CSS stylesheet.
Or we can have an ID, and apply attributes using javascript.
We can apply attributes with http headers, and the browser can negotiate the resource with http accepts and quality parameters.
We have video, audio, and object tags that can all have child elements.
We have query parameters and fragment selectors, and path parameters, and post parameters and accept parameters for negotiating and selecting content from a server. (Designed to include ampersands which have to be entity encoded when used in HTML!)
We have all these sophisticated overlapping complicated mechanisms for attaching attributes to elements in a webpage. We have huge pieces of software for parsing through this poorly thought through mess.
But no, not a single one of these is good enough for this problem. LET'S INVENT A NEW SYNTAX AND ADD TO THE HEAP OF IDIOCY.
[+] [-] mcobrien|14 years ago|reply
Using Javascript means you have to load scripts before the img tag, which can hurt performance.
Using http headers or a special URL format makes working with CDNs more difficult.
This is actually a tricky problem to solve and it looks like the authors have considered some of the above problems.
(I still hope they change it. Nested elements might be a way to go.)
[+] [-] hoppipolla|14 years ago|reply
Although in general things that make authoring easier are preferred, designs that are easy to implement in a bug-free way are generally preferred over designs that are complex and likely to lead to interoperability issues. After all, having to fight implementation differences is a rather common complaint about the web platform.
It also hasn't been clearly demonstrated that multiple elements are easier to work with. They are more familiar, but significantly more verbose. I don't know how that plays out in practice.
[+] [-] VMG|14 years ago|reply
[+] [-] necolas|14 years ago|reply
[+] [-] codeka|14 years ago|reply
[+] [-] alexchamberlain|14 years ago|reply
[+] [-] pbhjpbhj|14 years ago|reply
Whilst there will be ways to automate the setting of such img srcset attributes based on the device (eg the PHP method mentioned that relies on a cookie) this sort of tailoring for specific device [characteristics] seems wrong somehow.
IMO this would be better handled by devices declaring their preferred viewport and/or pixel density just as they declare language preferences now, ie browser headers. Then the server can be set to send different images based on the header values and we don't have to worry about having a massive "srcset" attribute on each image tailoring to 500 different device variants. A server config would specify what viewport ranges to use and tell the server how to modify the images sent (or modify the path, or modify the location - eg switch an image with a folder called image.jpg and have filename tagged images for the different variants handled).
Perhaps this seems hacky too ...
In any case the SRCSET attribute proposal here looks short-sighted and hackish to me.
[+] [-] WiseWeasel|14 years ago|reply
[+] [-] unknown|14 years ago|reply
[deleted]
[+] [-] ZenPsycho|14 years ago|reply
[+] [-] woodall|14 years ago|reply
[+] [-] WiseWeasel|14 years ago|reply
[+] [-] fiznool|14 years ago|reply
It takes the approach of setting a cookie when the page first loads with the viewport size, determined through media queries. Every request to the server then includes this cookie.
When an img is requested (as an <img> tag or through CSS background-image) the cookie is read to determine the viewport size of the client. The PHP script then serves up the most appropriate image size to the client.
The only thing you really need to do is add the .htaccess rule (to intercept image requests and route them through the PHP script), the php script itself and the highest resolution you need for each image. The script takes care of scaling down the image for smaller screens, caching them for later use.
I like the way this requires nothing on the client side, other than a cookie being set. All the heavy lifting is done on the server.
[+] [-] alexchamberlain|14 years ago|reply
Why not repurpose the media attribute from style tags to all other tags?
[+] [-] user24|14 years ago|reply
Yeah, stuff like "2x 100w" looks a bit like magic numbers[1]
Also there's potential for confusion in 'x' - does it mean X as in a co-ordinate i.e. width, or zoom? I'd rather see something more verbose like this:
Yes it's more wordy to write, but you read code more than you write it so it makes sense to optimise for readability over byte-shaving.[1] http://catb.org/jargon/html/M/magic-number.html
[+] [-] annevk|14 years ago|reply
[+] [-] bobsy|14 years ago|reply
I would rather see a solution implemented with CSS or even a meta tag.
<meta name="srcset" content="2x=HD; 100w=phone; 100w 2x=phone-HD" />
The above example is exactly the same information as in this link. However it is expressed in one place and thus is far simpler. The only reason to do this per image would be if you different naming conventions for individual images.. which would just be silly.
You could then have a nosrcset attribute which you can add to images which do not have high-res versions. This would save an http request.
[+] [-] tferris|14 years ago|reply
The browser should send the density of the screen in ppi (calculated by the screen resolution and the screen information provided by the OS) together with all the other standard stuff like OS, screen resolution, etc.
With this information the server can decide which images to send.
[+] [-] othermaciej|14 years ago|reply
[+] [-] ars|14 years ago|reply
It breaks caching completely.
It requires scripting just to serve an image.
The same url can have different data - imagine if you resume downloading a file, only to suddenly have a different file.
[+] [-] kennu|14 years ago|reply
[+] [-] mooism2|14 years ago|reply
I don't understand why that's maximum pixel density and not minimum pixel density.
If I'm using a super-retina device with 4x pixel density, surely it's better for me to get the 2x image than the default (presumably 1x) image?
[+] [-] annevk|14 years ago|reply
https://www.w3.org/Bugs/Public/show_bug.cgi?id=17057
[+] [-] benwerd|14 years ago|reply
What I'd love to see is something similar for bandwidth sets, so lower bandwidth connections can be sent lower quality images. And then for both features to be made available for video tags.
[+] [-] Kilimanjaro|14 years ago|reply
Bonus point, less cluttered HTML.
[+] [-] jacobr|14 years ago|reply
[+] [-] ars|14 years ago|reply
[+] [-] est|14 years ago|reply
Why not <img srcset="url_1" srcset="url_2">? Is this against SGML syntax?
[+] [-] Herover|14 years ago|reply
<img>
<source src="house-hd.jpg" width="100px" height="200px" density="2x" />
...
</img>
Or something like that.
[+] [-] mooism2|14 years ago|reply
There must be at least one height / width / pixel density descriptor for each url, so if you see a comma before the url ends, you know it must be part of the url.
[+] [-] karl_nerd|14 years ago|reply
When I saw the last line in the doc linked above, I realized that <img srcset=""> is probably optimized for adding one (1) "retina" image for iPhones and other high-DPI devices.
[+] [-] andybak|14 years ago|reply
[+] [-] jacobr|14 years ago|reply
[+] [-] pagejim|14 years ago|reply
http://testcases.glitchmr.pl/html/img-001.html
[+] [-] juddlyon|14 years ago|reply