【问题标题】:minification did not generate minified version缩小没有生成缩小版本
【发布时间】:2013-10-03 23:04:51
【问题描述】:

我正在创建一个 asp.net webforms 应用程序并尝试缩小我的 js+css 文件。我正在使用这些准则:http://blogs.msdn.com/b/rickandy/archive/2012/08/14/adding-bundling-and-minification-to-web-forms.aspx。

我的 web 应用程序的目标是 .net 4.0,但我将其更改为 .net 4.5。当我查看源选项卡中的 chrome developertools 部分并查看捆绑包时,它看起来不像已生成:

jquery?v=

我添加了 BundleConfig 类:

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/jscripts/jquery-{version}.js"));
        BundleTable.EnableOptimizations = true;
    }
}

在 jscripts 文件夹中,我得到了我的 js 文件:jquery-1.8.0.min.js 在主页的母版页中,我有:

<asp:PlaceHolder ID="PlaceHolder1" runat="server">
   <%: Scripts.Render("~/bundles/jquery") %>
</asp:PlaceHolder>

在代码 OnInit-event 后面的母版页中,我有:

BundleConfig.RegisterBundles(BundleTable.Bundles);

当我调试应用程序时,它会触发渲染语句。是不是我需要在不同的类中注册捆绑包?

【问题讨论】:

  • 不确定在 Web 表单中使用时是否是这种情况,但在 MVC 中,如果您正在调试(或者更多点在调试模式下编译),捆绑器将返回非缩小版本,请尝试切换释放模式并再次运行
  • 您的 jscripts 目录中是否有脚本的缩小版和完整版?
  • 您的问题现在解决了吗?

标签: jquery asp.net webforms bundling-and-minification


【解决方案1】:

为了能够在调试模式下查看缩小版本,您可以:

  1. 设置 BundleTable.EnableOptimizations = true;在你的 bundleconfig.cs 文件中
  2. 在您的 web.config 文件中设置编译 debug="false"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-02
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 2016-12-10
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多