【发布时间】:2012-11-02 19:18:05
【问题描述】:
ASP.NET 4.5 有一个很棒的新捆绑功能,并且似乎支持使用 CDN。 Microsoft 给出的使用 CDN 捆绑功能的示例是这样的
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 域的链接的前缀?
例如。
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>
【问题讨论】:
-
类似的问题 stackoverflow.com/questions/12047981/… 用您的自定义 cdn 替换 azure cdn
标签: c# amazon-cloudfront asp.net-4.5 bundling-and-minification