I am planning to use Azure CDN on the top of Sitecore Media library, from my understanding, Azure CDN does not support lazy loading and the only easy way is the root described in the Sitecore Azure CDN connector (basically creating MediaLibrary folder structure and files on the publish event) The problem that I can see it is with resized images, in Sitecore, you can call resize dynamically an item passing height and width in the url, but I am not sure how to handle this from the CDN point of view. Happy to know your opinion and workaround this limitation. Stelio
2 Answers
If you are using Azure PaaS and making use of WebRoles (such as when using the Sitecore Azure Module) then you should be able to more easily integrate the cloud service with Azure CDN.
I'm not sure exactly what your plans were with integrating with Azure, but rather than worrying about any Sitecore handlers and pushing files to Azure, I suggest that you configure the CDN endpoints and then redirect all your media request to the /cdn
folder. This will cause Azure to cache your dynamic content, taking into account any url parameters (like resizing). If the content is not cached then the request should be retrieved from Sitecore and then cached for any future requests, working like an edge caching server.
The easiest way to take advantage of this is to set the media prefix link:
<setting name="Media.MediaLinkPrefix" value="cdn/media" />
And then you can make use of the URLRewrite Module to map cdn/media
back to ~/media
. Or just add handlers for this in Sitecore also:
<customHandlers>
<handler patch:before="*[@trigger='~/media/']" trigger="cdn/media/" handler="sitecore_media.ashx" />
</customHandlers>
<mediaLibrary>
<mediaPrefixes>
<prefix value="cdn/media"/>
<prefix value="~/media"/>
</mediaPrefixes>
</mediaLibrary>
You may wish to only do this on your CD environments. Additionally, you could also take advantage of this for your static images. You would need to make sure they were all prefixed /cdn
also, but if the folder was /cdn/images
then you could have a different URL Rewrite Rule to map that back to /images
.
Some additional info:
- Using the Windows Azure Content Delivery Network (CDN) - read section
Using cloud services with the CDN
onwards - Publish Content to the Azure CDN with URLRewrite
- Integrate a cloud service with Azure CDN
Unfortunately I don't have access to an Azure instance so unable to test this.
UPDATE: I wrote an article on integrating Sitecore with Azure, although it's generic enough to work with any CDN provider and any version of Sitecore if you overwrite the media handler. You can read more here: Setting up Azure CDN to deliver your Sitecore Media
Well, maybe not a solution in your case, but I'd go for another CDN. This limitation in Azure CDN just puts too great constraints on your solution. As you describe, you should really utilize the resize function in Sitecore, in order to keep a good architecture and maintainable code.
Other people have also faced the same problem and went for other CDN options, such as Akamai and AWS CloudFront: http://feedback.azure.com/forums/169397-cdn/suggestions/3046714-custom-origin-support-to-cdn