Manually configure the Sitecore Media Library to use a CDN

Version: 10.4

This topic describes how to manually set up the Sitecore Media Library so it can use a Microsoft Azure® Content Delivery Network (CDN). This is helpful if you have an existing on-premise or Azure-deployed Sitecore instance, and you want to enable the Sitecore Media Library to use a CDN.

Note

If you are going to deploy a new instance of Sitecore XM or an XP scaled configuration on Azure, you do not need to set it up manually. Instead, you can use one of the following options: 

Prerequisites

Before you can set up the Sitecore Media Library to use a CDN, you must:

Manually configure the Sitecore Media Library

You manually configure the Sitecore Media Library so it can use a CDN:

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

  2. In App_Config\Include, create a folder named CDN.

  3. In the CDN folder, create a file and name it: CDN.config

  4. Edit the CDN.config file and save the following information to the file: 

    Note

    Instead of http://example.com, use the URL of your CDN endpoint.

    RequestResponse
    <?xml version="1.0" encoding="utf-8"?>
    
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    
        <sitecore>
    
            <settings>
    
                <!--  
    
                     
    MediaResponse.AlwaysIncludeServerUrl must be true, to always include CDN
    url when getting media item url.
    
                      Otherwise, the request will
    not be served by CDN server.
    
                -->
    
                <setting name="Media.AlwaysIncludeServerUrl">
    
                    <patch:attribute name="value">true</patch:attribute>
    
                </setting>
    
                <!--  
    
                     
    MediaResponse.MediaLinkServerUrl must be set to url of the CDN endpoint.
    
                      Change it from http://example.com, to the url of the CDN
    endpoint.
    
                -->
    
                <setting name="Media.MediaLinkServerUrl">
    
                    <patch:attribute name="value">http://example.com</patch:attribute>
    
                </setting>
    
                <!--  
    
                     
    MediaResponse.AlwaysAppendRevision should be true to always append
    revision when getting media item url.
    
                      The purpose of the value is
    to generate a unique URL for every revision.
    
                -->            
    
                <setting name="Media.AlwaysAppendRevision">
    
                    <patch:attribute name="value">true</patch:attribute>
    
                </setting>
    
                <!--  
    
                      MediaResponse.Cacheability
    must be Public to let the CDN server cache the response.
    
                      Otherwise instead of caching
    the response, the CDN server will ask for the response from Sitecore server
    every time. 
    
                -->
    
                <setting name="MediaResponse.Cacheability">
    
                    <patch:attribute name="value">Public</patch:attribute>
    
                </setting>
    
                <!--  
    
                     The max-age to use in media
    response headers.
    
                     CDN server uses this value as
    max-age of the response cache.
    
                -->
    
                <setting name="MediaResponse.MaxAge">
    
                    <patch:attribute name="value">7.00:00:00</patch:attribute>
    
                </setting>
    
            </settings>
    
        </sitecore>
    
    </configuration>
    Note

    You can also find this example configuration file under the root Sitecore folder in, App_Config\Include\Examples\CDN.config.example

    For more information about configuration values, see the Sitecore Media Library CDN-related configuration reference

  5. Ensure that any URL that has been created using one of the options mentioned in Developer considerations for the Sitecore Media Library CDN support, in the Getting a CDN-enabled Media Item URL section, includes a CDN URL and revision number.

Do you have some feedback for us?

If you have suggestions for improving this article,