igrigorik / http-client-hints

402 stars 24 forks source link

Knowing DPR before calling images #71

Closed karlcow closed 7 years ago

karlcow commented 7 years ago

@igrigorik During a discussion with a big Web site, they had this context.

  1. They send different image resolutions to different devices.
  2. They need to know it before the image call (so at the initial HTML request)

window.devicePixelRatio is not working and client Hints for Image HTTP Request is too late. I guess they built the URI in the template on the server side at the initial request.

Do you think client hints would be able to address this use case?

ejthurgo commented 7 years ago

Client Hints plans to solve exactly this. DPI is relatively easy to ascertain, however image size is much more difficult because the browser's look-ahead pre-parser wants to start downloading images before it's loaded CSS (i.e. before it knows how big the image needs to be). Your best bet for now is to use picture/srcset and request image sizes/dpi based on CSS style media queries (which are based on viewport width), which is definitely an improvement on UA sniffing.

igrigorik commented 7 years ago

@karlcow thanks for the feedback!

PTAL at the discussions in https://github.com/httpwg/http-extensions/issues/306 and https://github.com/httpwg/http-extensions/issues/307... we're working towards a solution to enable CH signals on the navigation requests there, which will cover the use case above.

(closing this, let's continue on httpwg issues linked above)