【问题标题】:ASP.NET ScriptBundle does not work with .min.js?ASP.NET ScriptBundle 不适用于 .min.js?
【发布时间】:2012-10-26 03:04:36
【问题描述】:

我可以使用下面的方法成功地将 jquery 库与 ASP.NET MVC 中的 ScriptBundle 包含在内

bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-1.7.1.js"));

但是,如果我更改为最小化库,我无法从浏览器中获取它

bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-1.7.1.min.js"));

代码有什么问题吗?

【问题讨论】:

  • 不再需要使用 min 脚本了。捆绑器会为您分装。

标签: javascript asp.net-mvc bundle


【解决方案1】:

尝试清除忽略列表。

public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.IgnoreList.Clear();

            // code cleared for clarity

        }
    }

【讨论】:

  • 太棒了!谢谢,我现在有更多选择!
  • 很好的快速修复以恢复工作,但请注意,您的某些通配符包含模式可能会选择您不想包含的脚本:请参阅 this answer to a related question 以了解 @987654323 中的默认值@是。
【解决方案2】:

除非EnableOptimizationstrueWeb.config 文件中的compile Element 中的debug 属性设置为false,否则不会捆绑或缩小文件。此外,不会使用.min 版本的文件,将选择完整的调试版本。 EnableOptimizations 覆盖了Web.config 文件中编译元素中的调试属性

more info

【讨论】:

  • BundleTable.EnableOptimizations = true;
【解决方案3】:

您的代码一切正常,就是这样,您可以尝试更改ignoreList

更多详情:mvc4 bundler not including .min files

【讨论】:

  • 感谢您指出这个问题,它帮助我弄清楚了 IgnoreList 默认包含的内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-10
  • 2012-09-16
  • 1970-01-01
  • 2012-09-14
  • 2020-05-26
相关资源
最近更新 更多