Sitecore Azure CDN Setup for Media

Sitecore website performance will impact if you have a large number of media items on pages and it comes from the media library. To increase performance, use a Microsoft Azure® Content Delivery Network (CDN) with Sitecore Media in your solution. 

Here in this blog post, I am discussing how to configure the Azure CDN with your Sitecore solution so that your media library items are retrieved from the CDN and increase performance.

If you are using Sitecore Managed Cloud Service then either you will already have CDN setup on your prod environment or you can create a service request to Sitecore to create an app service for CDN else you can refer to the Sitecore document about CDN setup considerations.

Configuration In Sitecore:

Before you can setup the Sitecore Media Library to use CDN in your solution you must have

  • Sitecore XP or XM 9.1 or later
  • CDN endpoint

Step 1: Go to the path {your Sitecore root instance}\App_Config\Include\Examples and copy the CDN.config.example file and paste it into your Visual Studio Solution and remove the .example extension.

Step 2: Edit the CDN.config file and update the following values:

Below you can find the details about each setting:

  • Media.AlwaysIncludeServerUrl: Set the value to true, to always include a CDN URL when obtaining a media item URL. Otherwise, the media URL will be generated without a CDN URL and the request will not be served by a CDN server. On the CD server, it should be true, and on CM false.
  • Media.MediaLinkServerUrl: Set the value to the URL of the CDN endpoint. (When you receive an item URL, this URL is included.)
  • Media.AlwaysAppendRevision: Set the value to true. The purpose of the value is to generate a unique URL for every revision by adding a query string parameter (rev) when you receive an item URL. This means every time an item is revised, a new URL is generated. It also prevents a CDN from returning old revisions.
  • MediaResponse.Cacheability: Set the value to the public, to let the CDN server cache the response. Otherwise, instead of caching the response, the CDN server will ask the Sitecore server for the response every time you request a media item. This value is set as a cacheability response header.
  • MediaResponse.MaxAge: The value of this setting determines the max-age in media response headers.  It is used to calculate the value of an expiration header. A CDN server uses this value as the max-age of the response cache.

Note: In case you want to remove the cache from the CDN you need to purge the CDN. You can do this manually by Purge option from the Azure portal CDN.

Reference:

azure-cdn-sitecore

Happy Sitecoreing ðŸ˜Š

Comments

Popular posts from this blog

Sitecore Installation Error: Failed to Start Service 'Sitecore Marketing Automation Engine'

Import CSV Data in Sitecore Using PowerShell: Part-3

Sitecore Technology MVP Journey 2022