【问题标题】:Bundling and Minification mvc4捆绑和缩小 mvc4
【发布时间】:2012-06-28 18:56:36
【问题描述】:

我为测试捆绑和缩小创建了一个 mvc4 应用程序,但是当我运行它并查看 html 呈现的代码时,我注意到了 不,我的 css 和 javascript 不是 Bundle

<link href="/Content/themes/base/jquery.ui.resizable.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.selectable.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.accordion.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.autocomplete.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.button.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.dialog.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.slider.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.tabs.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.datepicker.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.progressbar.css" rel="stylesheet" type="text/css" />

<link href="/Content/themes/base/jquery.ui.theme.css" rel="stylesheet" type="text/css" />

<link href="/Content/site.css" rel="stylesheet" type="text/css" />

但默认情况下,Visual Studio 添加到我的布局文件中

   @Styles.Render("~/Content/themes/base/css", "~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

所以我想知道为什么 css 和 javascript 不是 Bundle?

【问题讨论】:

标签: asp.net-mvc bundle


【解决方案1】:

我得到了同样的东西。当我将 web.config 更改为此时:

<system.web>
    <compilation debug="false" targetFramework="4.5" />
    ...
</system.web>

...它反而呈现这个:

<link href="/Content/themes/base/css?v=ps9Ga9601PrzNA2SK3sQXlYmNW3igUv5FOdOPWptyus1"
    rel="stylesheet" type="text/css">
<link href="/Content/css?v=VvXiCiApDAv4OzD9Y7PEaTL0kONCWIV6Skw7uh51PZk1" 
    rel="stylesheet" type="text/css">

【讨论】:

【解决方案2】:
 BundleTable.EnableOptimization = true;

在 Global.asax.cs 的 Application_Start() 方法中添加这行代码。这将覆盖 web.config 中的任何设置并启用优化。 更多详情Refer实现Bundling和Minification的视频教程

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-01
    • 2023-03-03
    • 1970-01-01
    • 2013-09-11
    • 2012-01-29
    • 1970-01-01
    • 2013-10-22
    • 2017-12-13
    相关资源
    最近更新 更多