-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Document how to serve webp / jpg based on accept header #21912
Comments
related: #3517 |
CDN already optimizes images to webp: $ curl -H 'Accept: */*' 'https://static01-nyt-com.cdn.ampproject.org/i/s/static01.nyt.com/images/2019/03/15/opinion/15stephensWeb/15stephensWeb-jumbo.jpg' -s | head -c 50
����JFIF��C
$ curl -H 'Accept: */*, image/webp' 'https://static01-nyt-com.cdn.ampproject.org/i/s/static01.nyt.com/images/2019/03/15/opinion/15stephensWeb/15stephensWeb-jumbo.jpg' -s | head -c 50
RIFF��WEBPVP8 ����*�>Q(�F#���#2)�� |
Hi @jridgewell ! Yup, I think we can word this better, but basically what @sparhami and I were talking about is actually how many browsers (FF, Safari) don't support webp, and therefore when webp is provided as default to |
Since the AMP cache already handles this, maybe it would be better let developers know about the same pattern (serving webp based on accept header) for non-AMP cache (but still optimized) pages rather than trying to implement this in AMP. |
I think this is a server concern and not AMP's. It doesn't matter what bytes are sent down for |
So it looks like the assumption
#18599 (short-circuiting webp on ios) still provides a benefit, but it looks like the main action item here then is just to document this and suggests user to follow the AMP Cache's lead server-side. The AMP Cache is so smart. =) |
One problem with the current approach is that we are doing a lossy -> lossy image conversion in the AMP cache to generate the webp version. It would be better for page authors to be able to run the image conversion based on a raw source image, or provide a lossless webp on the page. There is no reasonable way to do that currently, since simply using a lossless webp in the source document will not work correctly for all browsers visiting the origin page. |
Publishers can link to lossless PNG files, which will also be converted to webp images in the cache. |
But that wouldn't be very good bandwidth wise for users visiting the original (non-cached) page. Same with loseless webp actually. |
The server can decide what to serve to whoever requests the file. Having endpoints as 1-1 with some file is the wrong way to accomplish differentiated serving, you can serve multiple files from the same endpoint. It's not much different than the brotli/gzip compressed responses being served from the same URL (in this case, it just happens to be a lossy transformation that can happen).
|
Does the AMP cache generate lossy jpgs out of PNGs? That does not seem like the right thing to be doing. PNGs are a lossless format (and intentionally so). For example, you may use it for encoding a bitmaps. If the AMP cache is re-encoding PNGs into lossy formats for serving, that should be fixed. I suppose it could check the file extension from the request path, and if it is something like jpg, assume that this is not really supposed to be a lossless PNG, and only then re-encode the image. Is this something that actually exists, that we can recommend to developers? I think there is still a wider problem that not all serving platforms support this. You are turning something that was essentially static file serving into something dynamic. How does this work with various (non-AMP) caches? |
No, lossless will only be converted to optimized lossless. The image must already be lossy to be converted to an optimized lossy. |
Right, we want to create lossy images, using a lossless source, rather than doing a lossy to lossy conversion (not just for webp, but also for the different compression levels for srcset). We currently cannot do this. |
I see essentially 4 different image intents:
If the publisher intended to ship a lossless image to the user, they can send either PNG or WebP. The cache will optimize these to compressed lossless images. If the publisher intended to ship a lossy image to the user, they can send JPG or (lossy) WebP. The cache will optimize these to compressed lossy images. The case we're talking about here is when the publisher wants to ship a lossless WebP to a user or a lossy JPG. But why wouldn't they have just sent a high quality, but still lossy, WebP? |
To clarify: when we are creating compressed lossy images, we should start from a lossless source, rather than a lossy one. |
Are you sure? We already compress a JPG twice (it starts as lossy and we optimize it). Why wouldn't compressing a high-quality lossy WebP be acceptable? |
For example, the developer may not give us a super high quality source to begin with. They may assume that generating something for the largest mobile screen size is sufficient. However, in the mean time, we have decided to automatically lightbox (and allow pan-zoom) on all images in the page over a certain size. The ideal resolution for our zoomed in mode will be higher than the largest resolution they put on the page. We cannot do a lossy to lossy conversion where we increase the quality. I think it would be better to be explicit about what is the original source image, so we can create the right compression levels. |
I believe the Googlebot (the Google AMP cache's fetcher) will advertise WebP support, so you should be serving WebP to the cache.
Depending on the user's browser, we'll either serve the WebP or transform it to an acceptable format (either lossless PNG if the WebP is lossless, or JPG if the WebP is lossy). |
So it is intended that AMP can only be rendered on the server side? The cases you thereby exclude from use (that I can think of):
I find this approach questionable. note: |
The goal is to serve the same content to every browser: This means we get the benefit of static HTML pages, rendered by static CMSs and served by static serves. The CDN in front of your image has the ability to optimize the image responses for you, automatically. |
Stumbled over this as well. We currently suggest using However, I agree with @caroqliu and @sparhami that it'd be nice to have proper client-side support for webp. |
Yes, we should remove that. The recommended approach should be to serve webp when responding to the image request, if webp is advertised in the
There was discussion about this in ampproject/amp-wp#3082. As far as I'm aware, there is no good way to determine webp/formatX support on the browser side. |
@jridgewell did we ever consider generating a |
The For IE11, the fallback |
I believe |
One option would be for <amp-img width="550" height="368" alt="Mountains">
<source src="/static/inline-examples/images/mountains.webp" type="image/webp">
<source src="/static/inline-examples/images/mountains.jpg" type="image/jpeg">
</amp-img> When such an <amp-img width="550" height="368" alt="Mountains" class="i-amphtml-element i-amphtml-layout-fixed i-amphtml-layout-size-defined i-amphtml-layout" i-amphtml-layout="fixed" style="width: 550px; height: 368px;">
<source src="/static/inline-examples/images/mountains.webp" type="image/webp">
<source src="/static/inline-examples/images/mountains.jpg" type="image/jpeg">
<picture decoding="async" class="i-amphtml-element i-amphtml-layout-fixed i-amphtml-layout-size-defined i-amphtml-layout">
<source src="/static/inline-examples/images/mountains.webp" type="image/webp">
<source src="/static/inline-examples/images/mountains.jpg" type="image/jpeg">
</picture>
</amp-img> Then the codec selection would still be left up to the browser. |
I think that could be workable. Are you interested in bringing this up for a design review? |
I am interested but I probably won't have time to do so until Q3 or Q4 in the worst case. So if someone gets to it first, good on them. |
/cc @ampproject/wg-ui-and-a11y #21912 (comment) |
Happy to see this old bug picked up again! I'm going to remove my assignment from this issue since I probably won't be working on it anytime soon. =) |
I found https://github.com/jakearchibald/jakearchibald.com/blob/86fc3ccb22359b2fed177344d40e2554569ba909/shared/demos/2020/avif-has-landed/DecodedImg/index.tsx#L26-L47 today, which demonstrates how to use a native |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Two things need to be done:
Have a better way to load webp with amp img. We don't want to wait for it to fail to load before falling back to jpg.
Change the optimizer output both webp and jpg. There may be other formats to consider.
The text was updated successfully, but these errors were encountered: