ASP.NET MVC捆绑包优化导致Firefox中jQuery出错
我目前在让Firefox在EnableOptimization布尔值设置为true的情况下运行时遇到问题。目前,所有其他浏览器都在这种设置下完美运行,只有Firefox提供了一致的jQuery问题。如果我关闭EnableOptimizations,它在那里也可以正常运行 基本上,我的解决方案中有两个包。第一个包用作整个应用程序的基础,在_Layout.cshtml部分视图中调用。这里的文件是jQuery 1.11.3、jQuery UI、AngularJS等。第二个包是为特定视图对脚本进行分组。以下是BundleConfig文件的一般结构:ASP.NET MVC捆绑包优化导致Firefox中jQuery出错,jquery,asp.net-mvc,firefox,extjs,bundling-and-minification,Jquery,Asp.net Mvc,Firefox,Extjs,Bundling And Minification,我目前在让Firefox在EnableOptimization布尔值设置为true的情况下运行时遇到问题。目前,所有其他浏览器都在这种设置下完美运行,只有Firefox提供了一致的jQuery问题。如果我关闭EnableOptimizations,它在那里也可以正常运行 基本上,我的解决方案中有两个包。第一个包用作整个应用程序的基础,在_Layout.cshtml部分视图中调用。这里的文件是jQuery 1.11.3、jQuery UI、AngularJS等。第二个包是为特定视图对脚本进行分组。
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有这个问题,这怎么可能?我该如何解决这个问题?回想一下,除非有必要,否则我宁愿不接触模板中的任何现有脚本。事实证明,ExtJS脚本没有正确缩小,这就是Firefox给出这些错误的原因。在我的解决方案中,其他一切都正常