MVC4捆绑和缩小与CDN

时间:2013-09-06 20:20:14

标签: asp.net asp.net-mvc asp.net-mvc-4 cdn bundling-and-minification

我知道CDN的优点,我也了解MVC4捆绑和缩小提供的好处。

我想知道可以将MVC4捆绑和缩小以及CDN的优势结合起来。我的意思是我们可以将捆绑和缩小的脚本或css发布到CDN,然后在视图中我们通过CDN URL访问缩小版本吗?

2 个答案:

答案 0 :(得分:2)

是的,将Minified脚本发布到CDN是完全可能的,也是一种很好的做法。我经常在各种CDN上看到它们。这允许开发人员选择他们需要的版本。

...then in views we access the minified version through CDN url?

是的,您将使用CDN网址访问缩小版本。

答案 1 :(得分:0)

您可以将MVC4捆绑和缩小与CDN结合使用

http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

上面的代码:

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.
}
相关问题