Having issue with nextjs webp/avif image formats when deployed to netlify. It seem to be working fine locally and also on Vercel. Do I need to add any additional configuration in netlify?
hi there, when you say āhaving issueā can you explain a bit more? what kind of issues? do you have a screenshot or some logging info? that will help us troubleshoot.
NextJs provides an option to format images to webp format using the following setting in next config file.
images: {formats: [āimage/webpā] }
Looks like this is not working when deployed to netlify. I have attached screenshot of image load with Netlify and local run. You can see that it gets converted to webp format when I run locally but itās still jpeg on netlify.
Local Run:
Netlify Run:
Did you check this:
Is there any update to this issue since the last reply by chance? Iām having this exact issue and I have Edge Functions, and my images are small, yet I canāt get netlify to convert them when the site is deployed. Anything else Iām missing?
Hi @jontewks
Thanks for reaching out. Have you enabled the edge function IPX handling as seen here:
To turn on Edge image handling for Next/Image, set the environment variable NEXT_FORCE_EDGE_IMAGES to true
Thanks very much Gualter, that is the one I needed. I missed the mention of that in the docs and thought it would work out of the box since I had edge functions available. I appreciate the help!
@jontewks Hi! Since this thread is related Iāll ask here (in case let me know and Iāll move the question to a separated thread). I think thereās a problem with Nextjs runtime and image formats. In my nextjs Iāve specified I only wants formats: [āimage/webpā], but in Chrome I always get avif images, which in my case I donāt want to. Iāve also added the NEXT_FORCE_EDGE_IMAGES variable and setted to true but nothing changes.
Is there a way to fix this? Thanks!
Whatās the issue with AVIF? It is smaller in size than WebP, but anyways, if you can solve this by adding the following to a _redirects
file in the public
folder:
/_next/image url=:url w=:width q=:quality /.netlify/images?fm=webp&url=:url&w=:width&q=:quality 200!
Yes theyāre smaller but slower during decoding which can increase the LCP. Iāll try that, thanks for the info!