Azure CDN for Sitecore

What is CDN?

Definition

In simple words the website and assets are cached in multiple servers across the world. When a user visits the site they are served from the nearest server to their location to reduce latency and improve load times.

https://en.wikipedia.org/wiki/Content_delivery_network

Image Source

Why to use CDN?

The CDN helps in reducing the latency and download time. Since CDN will be a different domain, Help in concurrent download of assets.Improves page load time that gives a better User Experience. Having a better position in search engines. The number of website visitors who turn to customers.

  • Improve page load speed
  • Handle high traffic loads
  • DDos attack prevention
  • Reduce bandwidth consumption
  • Higher conversion rates
  • Scalability

Every Second Counts

Studies show that a second-long delay causes a 7% drop in conversions, an 11% drop in page views and a 16% drop in customer satisfaction.

Types of Azure CDN

I am mainly focusing on the CDN offerings on Azure. The following offerings are provided in Azure as endpoints.

CDN Marketplace offering

Pricing

The pricing is inexpensive compared to the value and speed that is provided by the Azure CDN.

https://azure.microsoft.com/en-us/pricing/details/cdn/#pricing

Feature

Azure Content Delivery Network (CDN) includes four products:

Limits

Limits to 25 CDN Profiles per Subscription. Limit 25 Endpoint per profile. Limit 25 Domains per endpoint.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/azure-subscription-service-limits#content-delivery-network-limits

How to enable CDN with Sitecore?

The CDN works for public facing websites. The CDN needs to access and replicate the CD server. We can use CDN in two ways for Sitecore right out of the box

  1. Media library items
  2. Static assets

Media Library items

On the Sitecore Content Delivery (CD) server, go to the Sitecore deployment folder.

  • In App_Config\Include, create a folder named CDN.
  • In the CDN folder, create a file and name it: CDN.config
  • Edit the CDN.config file and save the following information to the file:

https://doc.sitecore.com/developers/102/sitecore-experience-manager/en/manually-configure-the-sitecore-media-library-to-use-a-cdn.html

Ref:https://doc.sitecore.com/developers/101/sitecore-experience-manager/en/content-delivery-network.html

How to setup Azure CDN?

Create a new resource by searching for CDN

Compare the offerings screen choose Explore other offerings and Azure CDN Standard from Microsoft

Common Error if you have not registered the CDN Resource provider in your subscription

Follow the instructions in the article and enable Microsoft.Cdn, it will take few minutes before you can use it.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/resource-providers-and-types

Provide the information in the CDN profile creation page

Validation is passed review and create

Site will not be immediately available but will take some time depending on the size of the site.

Important Settings

First things to-do once created is to update caching rules by default its set to ignore the query strings. It needs to be updated to cache every unique URL that will help in reflecting the changes of media items when they are published.

Example URL of an image from Sitecore media library would be like the following



Its really important to enable that settings.

Purge

When the images or assets publised the revision guid in the Url should pull the new asset. If in case if you need to purge the CDN to force reload. Follow the purge option that could be done at the site level or a path.

Bonus Tip

The CDN can be setup with a custom domain and domain certificate will be provisioned without any additional cost for free by Microsoft.

WEBP support

If you have installed Dianoga it will support nextgen format webp. Azure CDN (Microsoft) Classic doesnt support it and Nehem has a solution for it in this article - https://www.nehemiahj.com/2022/08/sitecore-dianoga-with-azure-cdn.html

Ref:

https://jammykam.wordpress.com/2017/02/13/sitecore-azure-cdn/