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
Webp images using next/image are not converted to another format on incompatible browsers #20794
Comments
I try to change the local file in if (mimeType) {
contentType = mimeType
} else if (upstreamType?.startsWith('image/') && getExtension(upstreamType) && getSupportedMimeType([upstreamType], req.headers.accept)) {
// It should be considered whether the UA supports upstreamType
contentType = upstreamType
} else {
contentType = JPEG
} Another problems: If the web image contains transparent areas, it will be problematic to convert to JPEG. |
I'm having this problem as well. I've made a temporary fix on my site until this is solved. Hope it will be solved soon |
any news about this issue? |
The above PR looks like it still does not solve this issue. Correct me if I'm wrong, but if the source image is a webp it will still get served as a webp. |
The current implementation logic of image-optimizer.
So, if you want to use Note:Animated images have additional logic |
For me, this is not working. I am setting the images in JPEG format, hoping that it will convert it to webp for the browsers that support it, and it is not doing it. This is the way I am using it
And I added in the next.config.js the domains that I am using
|
“image-optimizer” confirm that the browser supports
next.js/packages/next/next-server/server/image-optimizer.ts Lines 326 to 329 in 4b587d3
|
The problem here is that the same accept header will be present for browsers that do not support webp, so Perhaps instead of looking at mime types, Google's recommended test method should be employed: // check_webp_feature:
// 'feature' can be one of 'lossy', 'lossless', 'alpha' or 'animation'.
// 'callback(feature, result)' will be passed back the detection result (in an asynchronous way!)
function check_webp_feature(feature, callback) {
var kTestImages = {
lossy: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",
lossless: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==",
alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
animation: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"
};
var img = new Image();
img.onload = function () {
var result = (img.width > 0) && (img.height > 0);
callback(feature, result);
};
img.onerror = function () {
callback(feature, false);
};
img.src = "data:image/webp;base64," + kTestImages[feature];
}
check_webp_feature("lossy", res => console.log(res ? "supported" : "unsupported") |
This code only work well for check local env. Note:image-optimizer is next- server's service. |
Correct, but the |
Good idea. But,can we change the default HTTP header when use img tag? If not,i have an idea. if browser support web. Is the cost too high? |
There would be need to transform anything in browser (and it's definitely the wrong way to go) - just provide an |
Experiencing the same issue here on a production site. The strange thing is that the same version of Safari on different machines behave differently here. |
@nmokkenstorm Is that due to different MacOS versions? |
Images are taking much more time to load on production - while using next/image and also not being converted to next-generation formats, What can be done in this case? |
Would love to have an integration solution with Vercel optimized Next/image, without resorting to a setup like https://github.com/cyrilwanner/next-optimized-images |
Why not use html to do the fallback. Newer browsers that support webp will load the source image url, older browsers fall back to the img tag with the jpg image. |
Maybe work well in Next v12. nextConfig = {
images: {
// ... other conf
format: ['image/webp', 'image/png', 'image/jpeg'],
}
} |
I'm having this problem as well. I've made a temporary fix on my site until this is solved. Hope it will be solved soon |
Hi what temporary fix did you make? |
This has been fixed on the canary channel. Please give it a try with |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
10.0.4
What version of Node.js are you using?
12.16.0
What browser are you using?
Safari <= 13
What operating system are you using?
MacOS, iOS
How are you deploying your application?
next start, externally hosted assets
Describe the Bug
If you pass an image src which is natively a
webp
to thenext/image
component, it is always served as a webp. Safari versions <= 13 do not include webp support so the image fails to load.The Accept header sent in the request to the
_next/image
endpoint from Safari looks like this:I believe the following code is at fault:
next.js/packages/next/next-server/server/image-optimizer.ts
Lines 234 to 240 in 356bcde
Expected Behavior
On browsers that do not support webp, files should be converted into
jpeg
orpng
(most likely jpeg?).To Reproduce
.webp
in yourpublic
folder or any other configured public host.next/image
component and set thesrc
prop to point to the.webp
image.Perhaps it would also make sense to add an optional
format(s)
query param which the server accepts, passed through as a prop?Also worth being aware of/considering is the HTML
<Picture />
tag (MDN Docs)Let me know if you'd like anything else from me, and I'll be happy to lend a hand :)
The text was updated successfully, but these errors were encountered: