Search code examples
imageazurecdnazure-cdn

Azure CDN caching for images, slow?


I have created an imageservice that can give me images with various sizes and effects.

Here's an example image:

https://nfimageservice.azurewebsites.net/image/b2daa6c7-256a-4e29-8a94-3056e3622dfb?width=720&width=480&fade=10&fluf=50

This is not a particularly fast service, so I wanted to speed it up a bit by using a CDN. This is the url to the CDN for the same image:

https://nfimageservice.azureedge.net/image/b2daa6c7-256a-4e29-8a94-3056e3622dfb?width=720&width=480&fade=10&fluf=50

As you can see the URL has Query String parameters that decides the size and effect.

In the setup of the CDN I have set the Query string caching behavior to Cache every unique URL

enter image description here

In the rules section I have tried the following:

enter image description here

The idea was to cache everything from the web app for 1 minute (this might change), but everything that comes from https://nfimageservice.azurewebsites.net/image/* with the querystring as part of the key, should be cached for 365 days. This is after all where the images come from.

I have tried loading the pages multiple times, waited for a long time before trying again, purged all the images from the CDN and so forth, but I still get loading times from azurewebsites that is faster than from azureedge. I realize I must have done something wrong, but I cannot for the life of me figure out what.


Solution

  • In fact, when you access your websites, the speed of using the CDN is relatively faster than without using CDN. It mainly depends on the networking environment where you access from your location to the CDN edge server location or other factors. See more details about How caching works.

    For example, if you locate in the East US, and the POP location is dispatched in Europe and your website is located in West US. Usually, the speed of directly accessing your website without CDN is faster than with CDN since the West US is more close to your location. Also, the global networking environment is not under control.

    For a short test, I add that image URI to my Azure CDN and have not set the rule engine. it's faster with CDN than directly access without CDN from my location.

    With CDN enter image description here

    Without CDN enter image description here