-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SW + Content-DPR: enabling correct intrinsic image size calculations #524
Comments
|
@annevk s/Request/Response/, right? Also, there is the case of fetching a binary blob (with XHR or fetch) and feeding said data to new |
If it is on the response, it seems a service worker could already set such a header. |
Thinking about this some more, it seems like we need something similar to
@yoavweiss sanity check? If that doesn't crazy, should probably move this discussion to whatwg, or some other place? |
Initializing an |
Moving discussion to ricg repo: ResponsiveImagesCG/picture-element#252 |
I'm seeing a bunch of img/picture experiments popping up that are using SW to rewrite requests on the fly to fetch optimized image assets, and there is a subtle gotcha that most of them will quickly run into...
UA "remembers" which DPR variant it picks when request is initiated and uses said value to determine the "intrinsic size" once the response is available - e.g. when rendering a 3x resource it needs to "scale down" the received image by a factor of 3, otherwise you'll get a really big and really blurry image.
However, if SW wants to synthesize / serve cached image response.. it doesn't know what DPR value UA is expecting (it only knows the request URL), and it can't tell the UA what asset DPR its returning either - e.g. was this request for a 2x asset request, and what if I'm offline but only have 1x asset that I want to return?
Alternatively, consider the case where we want to use SW to retrofit existing img markup to be DPR friendly - same problem. SW can rewrite requests and fetch correct DPR asset, but it can't communicate the intended DPR value to the UA.. which will result in UA rendering the image with incorrect dimensions.
tl;dr: I ran into same problem when working on Client Hints, and proposed solution is to add support for
Content-DPR
header, which would allow servers + SW to indicate the intended image DPR: http://igrigorik.github.io/http-client-hints/#rfc.section.5.1We have a prototype implementation in Chrome (slightly outdated, use "DPR" header):
While this is not a SW "bug", I want to raise this here as I'm sure it'll come up as a gotcha once more people start playing with SW. Should we make a push to ship above header as a standalone feature?
P.S. Landing support for
Content-DPR
would effectively mean that you can implement Client Hints via ServiceWorker, which is rather nice!The text was updated successfully, but these errors were encountered: