lorenzodejong / next-sanity-image

Utility for using responsive images hosted on the Sanity.io CDN with the Next.js image component.
MIT License
148 stars 19 forks source link

Webp on supported browsers #6

Closed surjithctly closed 3 years ago

surjithctly commented 3 years ago

First of all, thanks a lot for this plugin. It makes things easy.

next/image supports conversion to webp format on supported browsers. Similarly, Sanity also supports webp transformations. So, how can I use that feature while using your plugin? is it possible now? if yes, can you show an example? webp on modern browsers, JPG on old/unsupported browsers.

If no, I have realized you are also planning for a v2 release. Would you consider this feature as well?

Thanks again

~Surjith

lorenzodejong commented 3 years ago

Hey @surjithctly, thanks for opening this issue. I just noticed the Sanity CDN supports automatic content negotiation using the auto=format option. I've included this by default and released a 2.0.0 version which is now available on npm!

lorenzodejong commented 3 years ago

Do note that the URL still refers to the original content type (for example when the uploaded file is .png), but the returned content type is webp if this is supported by your browser. You can see this behavior in the network tab of your browser's devtools.

surjithctly commented 3 years ago

Awesome. Just tried and works perfectly. Thanks for fixing it quite fast 👍