Currently the UA "remembers" which DPR variant it picks when making a request and then uses said value to scale the received asset before it's displayed - e.g. if a 2x selector is used, then the image is automatically scaled down by same factor before its displayed.
However, there are cases where what the client chooses, and what comes back (from server, cache, service worker, etc), are not the same:
To address above use cases, we need two things:
img.density = 2.0
Yeah, I don't see anything wrong with the idea, and being able to set the default densities of things seems useful.
Are you just asking for the sizing algo to check this header on the response and respond accordingly?
Yes, I guess there are two different things here, although they are related in terms of API surface...
Just Curious to know. In the case of offline, Will it returns the image from cache and scales it automatically or wont render the image from cache?.
Presumably we'd have to cache its server-specified resolution along with it. Then it'd scale automatically.
HTTP response headers are cached (we need them for Accept+Vary processing, ETags, etc), so that's not an issue, the value will be available when coming from cache.
bump ... any blockers for making this happen?
It's not clear to me that Client-Hints will be adopted by all browsers. I would recommend monkey-patching HTML in the CH spec for the header part for now.
The JS API can be added, but I don't know what behavior you would like it to have. Should the default be a special "auto" value that has today's behavior, and if you set it to a number, that number gets used even if a new resource is selected? Or something else?
@zcorpan monkey patch HTML spec from an IETF doc? Yikes.. If anything, I think it would make sense to do the reverse: move Content-DPR from CH into HTML spec. It came about because we first stumbled into the need for this when working on CH, but it's useful (and needed) outside of CH - e.g. you're serving assets from a ServiceWorker and need to communicate the DPR of the asset, such that it's displayed correctly.
JS API: I'd expect the query to return the DPR of the current resource; if the resource changes it should return the new value.