3 ms·
I find this really disappointing, and it's another example of browser vendors and spec writers creating more problems than they solve. Even the best example her
by grey-area 13y ago
I find this really disappointing, and it's another example of browser vendors and spec writers creating more problems than they solve. Even the best example here falls short:
<source srcset="med.jpg 1x, med-hd.jpg 2x" media="(min-width: 40em)" />
and is fraught with problems. What does 1x and 2x mean in a world where devices range in ppi so dramatically, and single devices allow scaling from a rendered scale of 100ppi to 1000ppi (zooming on an ipad for example)? What actual resolution are these images (as opposed to display intent) and how do we find that out, by loading them all?
Including srcset in the picture element just makes things worse, not better, it's a confusion of a very good idea (allowing pictures to have multiple optional sources specified in the markup), and doesn't add any useful information, just gives hints as to rendering intent.
Here's how the concerns break down, from my point of view:
The HTML should provide a list of images to be displayed, in different formats and resolutions. It should not care about the device it is being rendered on, but it should provide as much info as possible on the source elements.
The CSS should specify the intent of the designer as to size and style (possibly suggesting different display sizes for different devices).
The User Agent (and thus the user) should be deciding which images to load and display based on the zoom level, the screen resolution, network, user preferences, and the image sizes available (as specified in html), designer intents, and future requirements we can't anticipate now. HTML works best when the markup doesn't try to second guess how it will be displayed and leaves that to UA.
srcset is a solution to a problem we didn't have, which will introduce all sorts of other problems in future (what is 2x resolution? how do we introduce new image formats?), and tries to stuff rendering intent into HTML where it doesn't belong. We'd be much better off looking at the picture element and improving it to include information on the actual image sizes (already possible), and letting the User Agent decide how to load and use those images.
Just as one example of unanticipated usage, a gallery plugin might read the source images available in some picture elements, and automatically construct a gallery from the thumbnails and hires images for each image. That's not possible with srcset and 1x 2x etc, but it is if picture elements have multiple sources at different specified sizes. e.g.:
<picture>
<source src="myjpg.jpg" width=100 height=100>
<source src="myjpglrg.jpg" width=1000 height=1000>
<img src="myjpg.jpg" alt="fallback img tag or text">
</picture>
Something is really broken with the webkit consultation process if changes like this can make it into the browser.
- cgrand-net 13y agoCSS px unit is not device pixel anymore. In this context 2x does not mean that the image is twice as big in px but that it should be used if the device pixel/px ratio is >=2
- grey-area 13y agoWhere did I make that assumption? Concentrating on device resolution ignores many of the other bits of information a browser has when deciding which images to load. What happens when the device pixel ration is < 2, but the device is zoomed on the web page? What about slow connections on retina devices, or users who prefer to load things faster by getting lores images (something specifically called out in the spec)? Or some new browser which gets incredible first page render speeds by loading thumbnails of all images, and only loading hires images for those displayed? Or scripts which want to enumerate images and choose a certain resolution, independent of the intended display size? This proposal is just making life easier for browser makers who want to cater for 2 resolutions in a hurry (ipad Retina, iPad), not for the people reading pages or creating them, and it puts the decision as to which image to render in the wrong place anyway IMHO. That should be a browser decision, based on data in the HTML.
- jcampbell1 13y agoThe reason webkit implemented srcset is because of the performance it allows. Consider: <img src="picture.jpg" srcset="picture@2x.jpg 2x" /> When the browser comes across this markup, it can request the correct image prior to finishing parsing the DOM or the CSSOM being ready. I understand the appeal of <picture>, but the browser cannot choose the correct image until the DOM is parsed, the CSSOM is ready, and the page has been layed out. That all happens much later, which means the page will load slower. I like the idea of <picture> but srcset is ideal if the only features you want are pre-loading and high-res support.
- grey-area 13y agoDo you have a mailing list discussion you can link to on this, that might be illuminating? The reason webkit implemented srcset is because of the performance it allows. I wonder what HTML would look like if browser performance was the primary concern? Is this truly the best argument for srcset, that browsers can parse the page quicker? Probably the fastest HTML to render would be something like this: <img src="foo" border="2px solid red" margin="10px" width="100px" height="100px" align="left"> There are good reasons we've moved away from that, even though it hits performance. It just seems wrong to be tying image resolutions to particular screen resolutions and trying to specify sources in a comma separated list with arbitrary resolution scales included, that's pretty nasty and not at all like other parts of HTML (which generally has been kept surprisingly clean if spartan in terms of features). I'd rather use js to load hires than use this or just serve everyone hires. It reminds me of the horrible multiple resolution handling on iOS, which is probably what inspired it (@2x etc). I think there are now 15 different icon sizes for iOS [1] because of this insistence on tying resolutions to device specs. I can imagine issues with devices lying about resolution or ending up between x1 and x2 and not getting bigger images just because their resolution isn't quite x2 etc. [1] http://mrgan.tumblr.com/post/708404794/ios-app-icon-sizes http://mrgan.tumblr.com/post/708404794/ios-app-icon-sizes I see the concern on loading - if CSS determines the resolution of images, that would have to be parsed before deciding which image option to fetch, but that could be addressed by letting the browser decide which images are appropriate, and if necessary changing them if the CSS overrides that later. However I think the browser has far more pertinent info than the CSS writer (as long as it knows what size images actually are, not the intended device resolution in 2013!) about network, device, images, performance, user prefs etc. - the browser should decide what size of image is appropriate, and should be given the info to do that, and speed of loading should not be the primary concern in designing a document format - that should be a worry for browser makers, not for readers or writers of HTML. The most convincing argument on the article page for me was a short comment pointing out the problem with srcset that it is tied to our expectations today of device specs: If LG releases its Quad HD(?) smartphone screen it still means changing the html if you want to support it. - Niels Matthijs Anyway, rant over, apologies for the long posts, I'll get back to work now, and thank you for taking the time to explain.