Developer considerations for the Sitecore Media Library CDN support

Abstract

Information about settings, pipelines, and details, which relate to Sitecore Media Library Content Delivery Network (CDN) support.

This reference contains information about settings, pipelines, and details which relate to Sitecore Media Library Content Delivery Network (CDN) support.

When you use a CDN for the Sitecore Media Library, the media item URLs of a page must be absolute URLs that start with a CDN URL, otherwise the Sitecore CD server will respond to every request instead of just the CDN server. 

To ensure that Media Item URLs respect the Sitecore Media Library, you can use the settings in the following table to address the media item.

Setting

Description and code sample

MediaManager

Use MediaManager.GetMediaUrl to obtain a CDN-enabled URL for the item.

<%
    Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem("path to media item");
%>
<img src="<%=Sitecore.Resources.Media.MediaManager.GetMediaUrl(item)%>"/>

sc:Image tag

If the item has an Image field, you can use the sc:Image tag to render the image so it has a CDN-enabled URL.

<sc:Image ID="image1" Field="ImageFieldName" MaxWidth="100" runat="server" />

sc:Link tag

If the item has an Image field, you can use the sc:Image tag to render the image so it has a CDN-enabled URL.

<sc:Link ID="link1" Field="LinkFieldName" runat="server" />

sc:FieldRenderer tag

If the item has a Link field or an Image field, you can use this tag to render the link so it has a CDN-enabled URL.

<sc:FieldRenderer ID="image1" FieldName="ImageFieldName" Parameters="w=100" runat="server" />
<sc:FieldRenderer ID="link1" FieldName="LinkFieldName" runat="server" />

Media items in RichText fields

If you use the rich-text editor to insert a MediaItem in a RichText field, the media item will be rendered using a CDN-enabled URL at run-time.

Note

If you are using the Sitecore Content Editor and at run-time want a media item to be rendered by using a CDN enabled URL, then do not use any of the settings in the table above. Instead, use the rich text editor to insert a MediaItem in a RichText field.

The pipeline getMediaUrlOptions impacts on the generation of Media Item URLs, and the getResponseCacheHeaders pipeline impacts on setting response cache headers. 

Note

Other modules may add some processors depending to the requirements.

getMediaUrlOptions

Using this pipeline, you can add processors to get media URLs and control the way a URL is generated for a media item. For example, when developers call a MediaManager.GetMediaUrl they can manipulate MediaUrlOptions in the processors. In this pipeline, the following processors impact on AlwaysIncludeServerUrl:

  • SecurityProcessor - This applies security concerns to MediaUrlOptions that have been provided by the pipeline argument. If the item is not publicly readable, SecurityProcessor sets the value of AlwaysIncludeServerUrl to false, unless it has been explicitly assigned by developer code or another pipeline.

  • SiteModeProcessor - This applies site mode concerns to MediaUrlOptions that have been provided by the pipeline argument. If the site mode is not normal, it sets AlwaysIncludeServerUrl to false.

getResponseCacheHeaders

This pipeline is responsible for providing response cache headers. The following processors impact on the cache headers for a media request:

  • RequestTypeDetectionProcessor - This detects the request type, if the request type has not been specified.

  • MediaRequestArgsInitializerProcessor - This initializes the getResponseCacheHeaders that have been provided by the pipeline argument for a media request. The values are determined by the Sitecore Media Response configurations in the Sitecore.config file.

  • PublishingProcessor - This applies publishing concerns on cache headers when creating a response. This processor sets cacheablity and the expiration date based on the publishing information of the item. If the item does not have any publishing date restrictions, both the expiration date and the max-age are determined by the Sitecore Media Response configurations in the Sitecore.config file. If an item has a publishing date restriction, the expiration and max-age is set so as not to exceed the maximum publish date of the item.

  • SecurityProcessor - This applies publishing concerns on cache headers when creating a response. If the item is not publicly readable, the processor sets cacheability none and set cache as expired.