ASP.NET 4.5有一個很棒的新綁定功能,並且似乎對使用CDN有一定的支持。微軟使用了CDN的捆綁功能給出的例子是這樣的使用ASP.NET 4.5捆綁和一個CDN(例如,CloudFront)
public static void RegisterBundles(BundleCollection bundles)
{
//bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
// "~/Scripts/jquery-{version}.js"));
bundles.UseCdn = true; //enable CDN support
//add link to jquery on the CDN
var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",
jqueryCdnPath).Include(
"~/Scripts/jquery-{version}.js"));
// Code removed for clarity.
}
這似乎表明,你需要的路徑明確告訴它你的CDN文件。
CloudFront CDN(我認爲還有很多其他的)爲您提供了一個反映您自己的子域。當你點擊http://uniquesubdomain.cloudfront.net/js/myfile.js?v=1
它提供了http://mydomain.com/js/myfile.js?v=1
這樣你可以簡單地前綴所有鏈接http://uniquesubdomain.cloudfront.net/
和你的文件是服務器從CloudFront。
ASP.NET 4.5捆綁功能是否與此類型的CDN兼容?是否有內置的方法可以將綁定功能的所有鏈接添加到您的CDN域?
EG。
bundles.UseCdn = true;
var myBundle= new ScriptBundle("~/bundles/js", "https://uniquedomain.cloudfront.net/");
myBundle.Include("~/js/file1.js");
myBundle.Include("~/js/file2.js");
會導致
<script src="https://uniquedomain.cloudfront.net/bundles/js?v=6y-qVPSK3RYOYHfPhOBDd92H4LjEjs-D3Hh2Yml6CXA1"></script>
類似的各種問題http://stackoverflow.com/questions/12047981/how-to-upload-bundled-and-minified-files-to-windows-azure-cdn,just通過更換Azure CDN向您定製cdn – Cris