4

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

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

4

2 回答 2

2

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

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

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

于 2013-09-06T20:25:47.970 回答
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.
}
于 2014-05-08T16:09:55.630 回答