Microsoft cdn returns webp image instead of original image when request header allows it

Ropyz37 6 Reputation points
2021-02-11T17:57:06.963+00:00

Hello,

Here is some context :

I am developing a static website hosted on a azure storage account.

The images for this website are located in the storage account in a folder at the same place as the html/js/css files.

Those images are stored in their base format and have already been converted to the webp format.

So for every images, there is a second image with the same name but not the same format (image1.jpg and image1.webp for example)

All the files are served throught a Microsoft Azure CDN (not Verizon nor Akamai).

Now, here is my problem :

When a request to get an image from the storage account is made, if the header of the request contains image/webp in the accepted format, then I want to get the webp formated image instead of the base format.

For example :

1.  A request is made to get the image named image1.jpg
2.  The request headear contains accept: image/webp
3.  There is an image named image1.webp in the storage account
4.  The CDN returns image1.webp instead of image1.jpg

In this example, image1.jpg should be retrieved only if image1.webp doesn't exist on the storage account or if the headear doesn't contains accept: image/webp.

Currently, I have tried a lot things, but the CDN always return the image in it's base format even if all the conditions are met.

Since there is a similar functionality that already works for getting compressed files in fomats like gzip or br instead of html/css/js for the website files, I think there is no reason that it's impossible to do with image formats.

So what am I missing, is there a way like redirecting the response or rewriting the URL through a rule, or maybe just a parameter somewhere to make that work. Or is it just impossible with a Microsoft CDN ?

Thanks by advance for your help ;)

Azure Content Delivery Network
{count} vote

2 answers

Sort by: Most helpful
  1. Sergio Solorzano 26 Reputation points
    2021-03-01T20:39:06.633+00:00

    Hello,

    I have the same problem with MSFT CDN (not VZ or AKAMAI), can someone please shed light? Please see below

    I also tried adding the following rule to no avail:

    73097-rules2.jpg

    Request:
    Accept: image/avif,image/webp,image/apng,image/svg+xml,image/,/*;q=0.8
    response:
    Content-Type: image/jpeg
    Vary: Accept

    Thank you for your help, Sergio

    0 comments No comments

  2. Gregor Srdic 1 Reputation point
    2022-02-18T12:19:52.777+00:00

    Anyone able to solve this with Azure Standard CDN yet? I am trying to implement a URL rewrite rule, but I can not figure out how to write rule that would rewrite each image file to a corresponding webp counterpart (/**/*.jpg to /**/*.webp) :(
    175828-image.png

    0 comments No comments