Live data from Hacker News

How to think about HTML responsive images

danburzo.ro

11–20 of 47 posts

Re: How to think about HTML responsive images

#11
To be honest ... this is IMHO by far one of the most complicated thing in the whole webdev area. I don't get it why ppl complain about how difficult CSS is ... but to foresee how an image behaves and find a good balance between size and file size is a hart thing to juggle with.

This article clarifies a lot of things for me so thx for that.

Re: How to think about HTML responsive images

#12
post #9

I have no idea why browsers moved away from providing the DPR (device pixel ratio) header on media requests so one could continue using the sensible and simple whilst the server could return the correct images on its own. Would love to know the rationale.

I haven’t followed Client Hints closely, but a change[1] in RFC 9842 internal drafts “removed specific features to be defined in other specifications”, and the `DPR` header ended up as `Sec-CH-DPR` in the nascent Responsive Images Client Hints spec[2].

[1] https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-cli... [2] https://wicg.github.io/responsive-image-client-hints/#sec-ch...

Re: How to think about HTML responsive images

#13
post #9

I have no idea why browsers moved away from providing the DPR (device pixel ratio) header on media requests so one could continue using the sensible and simple whilst the server could return the correct images on its own. Would love to know the rationale.

The server doesn't know what size the image will be displayed, but the browser does.

Re: How to think about HTML responsive images

#14
One frequent unpleasant side-effect of responsive design, is sites that resize themselves when you try to zoom the page. For images, this sometimes turns bizarre: If you try to zoom the current webpage to more clearly see details of an image, the web page will try to "help" you by resizing the image to continue to fit in your viewport. The net result is, that the image often gets even smaller when you try to zoom (because neighbour elements like text still grows). Reddit is one of the sites guilty of this. Worse, they even do it if you "open image in new tab". I have surrendered on this, and instead just DOWNLOAD the image to disk, to then reopen it in a separate tab, to finally zoom it.. Sigh.

Re: How to think about HTML responsive images

#15

Looks like the verbose approach would be the most advantageous for backwards and forwards compatibility

Having the server decide the image format based on the accept header is simpler. Services like https://imagekit.io/ (no affiliation) can do that for you.

Yes, a smart server (that does more than serve static image assets) can do the heavy lifting and alleviate some of the HTML markup complexity.

It has the `Accept` header as a guide to what image formats the client supports, and with Responsive Image Client Hints[1], it can opt into more info from the client (device pixel ratio, image layout width, viewport width).

Without relying on server features, `` with `` is the way to serve images in newer formats without breaking in less capable browsers.

It’s interesting that `image-set()`, the CSS sort-of counterpart to ``, bakes in the media type along with the resolution in a single syntax [2]. Which you could potentially see happening in `srcset`, but it makes the descriptive/prescriptive boundary a bit blurry, so it would complicate things IMO.

[1]: https://wicg.github.io/responsive-image-client-hints/ [2]: https://developer.mozilla.org/en-US/docs/Web/CSS/image/image...

Re: How to think about HTML responsive images

#16

To be honest ... this is IMHO by far one of the most complicated thing in the whole webdev area. I don't get it why ppl complain about how difficult CSS is ... but to foresee how an image behaves and find a good balance between size and file size is a hart thing to juggle with. This article clarifies a lot of things for me so thx for that.

I dont think topic thst can be explained in one blogpost is the most complicated thing in webdev.

People often just dont understand srcset/sizes and try to do too much and make some kind of media queries logic instead of leaving all to browser.

Re: How to think about HTML responsive images

#17
Is it possible to serve one image file of progressive encoding and display different size on different media conditions?

As a hack I would just put the blob offset in the URL as part of file name, and use js to load those images.

For example:

filename.1000-120w.3000-240w.5000-360w.jpg

means the 0-1000 bytes will get you 120w image, 0-3000 bytes will get you the 240w image, 0-5000 bytes will get you the 360w image, and load full will get you the original image. Make an http request with a Content-Range header and render the result with canvas or something.

Re: How to think about HTML responsive images

#18

One frequent unpleasant side-effect of responsive design, is sites that resize themselves when you try to zoom the page. For images, this sometimes turns bizarre: If you try to zoom the current webpage to more clearly see details of an image, the web page will try to "help" you by resizing the image to continue to fit in your viewport. The net result is, that the image often gets even smaller when you try to zoom (be…

Oh yeah, definitely something I’ve witnessed and been frustrated by before. Some of it stems from improper use of CSS units [1], and the only real recommendation I have is for people to _test_ for basic things like zooming in and out of the page, while keeping close in mind _the reasons_ people might want to zoom in and out of the page.

[1] https://ashleemboyer.com/blog/why-you-should-use-px-units-fo...

Re: How to think about HTML responsive images

#20

To be honest ... this is IMHO by far one of the most complicated thing in the whole webdev area. I don't get it why ppl complain about how difficult CSS is ... but to foresee how an image behaves and find a good balance between size and file size is a hart thing to juggle with. This article clarifies a lot of things for me so thx for that.

> I don't get it why ppl complain about how difficult CSS is ...

It's a huge language. There are so... many... properties.

Post reply on HN