Umbraco Azure CDN Toolkit
The AzureCDNToolkit package allows you to fully utilise and integrate the Azure CDN with your Umbraco powered website using a "Origin Push" approach.
To Push or to Pull You can use both a Push or a Pull origin approach to the Azure CDN with Umbraco since the release of the new Azure CDN (AzureEdge), this package supports only Push origin (storage) currently however it maybe extended to also support Pull in the future.
There are three file types that should be served from CDN if you have one.
- Assets - css, js & static images used by templates etc..
- Images managed by Umbraco - cropped or not
- Files - pdfs, docx etc
Once installed and setup the package provides UrlHelper methods to use for resolving url paths for assets and Image Cropper urls and also a value converter for the TinyMce editor so that images within the content are also resolved.
@Url.ResolveCdn("/css/style.css") @Url.GetCropCdnUrl(Umbraco.TypedMedia(1084), width: 150) <div class="brand" style="background-image: url('@Url.ResolveCdn(home.GetPropertyValue<string>("siteLogo") + "?height=65&width=205&bgcolor=000", false, false)')"></div>
When using these methods, the toolkit will attempt to resolve the urls to their absolute paths and crucially ensures that a cache busting querystring variable is added. Without the cache busting using the Azure CDN can become tricky when you want to update with new content. This has the added benefit of avoiding your site needing to handle any 301 redirects and also gets some optimisation benefit (PageSpeed etc).
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<a href="/media/1050/blank.docx">Download Word Doc</a>
<link rel="stylesheet" type="text/css" href="https://azurecdntoolkitdemo.azureedge.net/assets/css/bootstrap.min.css?v=0.0.1">
<a href="https://azurecdntoolkitdemo.azureedge.net/assets/media/1050/blank.docx?rnd=131070387800000000">Download Word Doc</a>
Note: this package is not compatible with Slimsy v1 (it should work with the upcoming Slimsy v2 using img srcset)
Both NuGet and Umbraco packages are available.