2

I have a web site to be hosted in Azure that has a lot of javascript and CSS but very small pages. I would like to have the javascript and the CSS delivered via a CDN.

Azure provides a really neat and convenient mechanism to allow this as described here https://azure.microsoft.com/en-us/documentation/articles/cdn-cloud-service-with-cdn/#integrate-aspnet-bundling-and-minification-with-azure-cdn

In short, you add the following code to your BundleConfig.cs

bundles.UseCdn = true;

var version = System.Reflection.Assembly.GetAssembly(typeof(Controllers.HomeController))
    .GetName().Version.ToString();
var cdnUrl = "http://axxxxxx6.vo.msecnd.net/{0}?v=" + version;


ScriptBundle scriptBundle = new ScriptBundle("~/bundles/xx", string.Format(cdnUrl, "bundles/xx"));

scriptBundle.Include(
            "~/Scripts/modernizr-*",
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/jquery.signalR-{version}.js",
            "~/Scripts/jquery.watermark.js", ....

I have followed the instructions to the letter and on the surface it appears to work exactly as expected.

But I realised that the caching for these CDN provided resources is disabled. Every time the web page is requested the JS and the CSS are downloaded again - which defeats the purpose of the CDN altogether.

enter image description here

I have also included the following in the web.config

    <staticContent>
       <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="15.00:00:00"/>
    </staticContent>

What am I missing here?

Thanks in advance.

Dave A

DJA
  • 661
  • 1
  • 9
  • 25
  • I don't think it has anything to do with Azure. In fact, I believe it's due to the fact that we use a custom "version" string. – Riwen Feb 21 '16 at 21:02

0 Answers0