MVC bundle with Azure CDN

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.

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

链接地址: http://www.djcxy.com/p/62722.html

上一篇: 如何清除Azure CDN以刷新任何缓存的内容?

下一篇: MVC捆绑Azure CDN