web.config - How to serve jpg/png as webp and avif if exist in IIS web.config?

88 Views Asked by At

Currently, I'm using:

location ~* ^(/.+)\.(jpg|jpeg|jpe|png|webp)$ {
  add_header Vary Accept;
  try_files $1.avif $1.webp $uri =404;
}

in nginx so that if it is going to load image.jpg or image.png and there is the avif format it will load image.avif. It will load image.webp if the avif doesn't exist and finally, if none of them exist, it will load the main image which can be jpg or png. Otherwise, a 404 page will return. Now I want to have it in web.config in IIS. Or the question could be How to convert the code above from nginx format to web.config?

0

There are 0 best solutions below