【发布时间】:2016-02-14 01:27:07
【问题描述】:
我目前在将 EnableOptimization 布尔值设置为 true 的情况下运行 Firefox 时遇到问题。目前,所有其他浏览器都在此设置下完美运行,只有 Firefox 给出了一致的 jQuery 问题。如果我关闭 EnableOptimizations,它在那里也可以正常运行。
基本上,我的解决方案中有两个捆绑包。第一个包用作整个应用程序的基础,在 _Layout.cshtml 部分视图中调用。位于此处的文件有 jQuery 1.11.3、jQuery UI、AngularJS 等。第二个包是对特定视图的脚本进行分组。下面是 BundleConfig 文件的一般结构:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.FileSetOrderList.Clear();
bundles.IgnoreList.Clear();
bundles.UseCdn = true;
Bundle baseBundle = new Bundle("~/bundles/Base");
baseBundle.Include("~/Scripts/jquery-1.11.3.js")
// Includes omitted due to large number of scripts
Bundle indexBundle = new Bundle("~/bundles/Index");
// Includes omitted due to large number of scripts
bundles.Add(baseBundle);
bundles.Add(indexBundle);
#if !DEBUG
BundleTable.EnableOptimizations = true;
#elif DEBUG
BundleTable.EnableOptimizations = true;
#endif
}
捆绑包本身包含 30 个或更多脚本,所以我无法告诉你我得到了多少错误,但这些错误都会导致相同的问题,这是我的解决方案中 jQuery 的问题。一些例子:
Ex.1:
TypeError: $.fn is undefined
().height("")}}function customScroll({$.fn.mCustomScrollbar&&$(".withScroll").e...
Ex.2:
TypeError: $(...).on is not a function
function toggleBuilder() {
$('.builder-toggle').on('click', function () {
if ($('#builder').hasClass('open')) $('#builder').removeClass('open');
else $('#builder').addClass('open');
});
}
$(document).ready(function () {
toggleBuilder();
});
大部分错误都来自我购买的模板,所以我宁愿不直接接触这些脚本。
这种行为对我来说似乎很奇怪,因为 jQuery 是在此页面上加载的第一个脚本,所以在我看来,任何脚本在加载之前都不可能使用 jQuery。更奇怪的是,只是 FireFox 导致了这个错误。
任何想法可能是什么原因? 也许其他一些脚本正在覆盖 jQuery?如何轻松识别?
更新: 经过一番研究,我决定提醒 $ 的含义。在 Chrome 和其他浏览器中,它返回正确的代码。然而,在 Firefox 中,它会返回:
function (out,values,parent,xindex,xcount,xkey) {
var c0=values, a0=Array.isArray(c0), p0=parent, n0=xcount, i0=xindex, k0, v;
if ((v=values['prefix']) != null) out.push(v+'')
out.push('/')
if ((v=values['entityName']) != null) out.push(v+'')
}
事实证明,这是 Sencha ExtJS 代码。现在这是我更新的问题:这怎么可能只有 FireFox 有这个问题,我该如何解决这个问题?回想一下,除非有必要,否则我宁愿不要触及模板中的任何这些现有脚本。
【问题讨论】:
标签: jquery asp.net-mvc firefox extjs bundling-and-minification