简体   繁体   English

ASP.NET MVC捆绑优化导致Firefox中的jQuery错误

[英]ASP.NET MVC Bundle optimizations causing errors with jQuery in Firefox

I am currently experiencing issues with getting Firefox running with the EnableOptimization boolean set to true. 目前,在将EnableOptimization布尔值设置为true的情况下运行Firefox时遇到问题。 For the moment, all other browsers are running perfectly under this setting, only Firefox is giving consistent jQuery issues. 目前,所有其他浏览器在此设置下均能正常运行,只有Firefox出现了一致的jQuery问题。 If I turn the EnableOptimizations off, it also runs okay there. 如果我关闭EnableOptimizations,它也可以在那里正常运行。

Basically I have two bundles in my solution. 基本上,我的解决方案中有两个捆绑软件。 The first bundle is used as the base for the entire application, which is called in the _Layout.cshtml partial view. 第一个捆绑包用作整个应用程序的基础,在_Layout.cshtml部分视图中称为该捆绑包。 Files located here are jQuery 1.11.3, jQuery UI, AngularJS, etc. The second bundle is grouping the scripts for a particular view. 此处的文件为jQuery 1.11.3,jQuery UI,AngularJS等。第二个捆绑包将特定视图的脚本分组。 Here is the general structure of the BundleConfig file: 这是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
    }

The bundles themselves contain 30 or more scripts together, so I cannot tell you how many errors I get, but the errors all lead to the same issue, which is something is wrong with jQuery in my solution. 捆绑包本身包含30个或更多脚本,因此我无法告诉您遇到了多少错误,但是这些错误均导致同一问题,这是我的解决方案中jQuery的问题。 Some examples: 一些例子:

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();        
});

Most of the errors occur from a template that I bought, so I'd rather not touch these scripts directly. 大多数错误是由我购买的模板引起的,因此我不希望直接接触这些脚本。

This behavior seems strange to me, because jQuery is the first script that is loaded on this page, so it seems to me it's impossible for any script to use jQuery before it is loaded. 这种行为对我来说似乎很奇怪,因为jQuery是此页面上第一个加载的脚本,因此在我看来,任何脚本都无法在加载前使用jQuery。 It's even stranger it's just FireFox that causes this error. 甚至更奇怪的是,正是FireFox导致了此错误。

Any ideas what the reason could be? 任何想法可能是什么原因? Perhaps some other script is overriding jQuery? 也许其他脚本会覆盖jQuery? How can I easily identify this? 我如何轻松识别这一点?

Update: after some research, I decided to alert the meaning of $. 更新:经过一番研究,我决定提醒$的含义。 In Chrome and the other browsers, it returns the right code. 在Chrome和其他浏览器中,它返回正确的代码。 In Firefox however, it returns this: 但是,在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+'')
    }

As it turns out, this is Sencha ExtJS code. 事实证明,这是Sencha ExtJS代码。 Now here's my updated question: how is this possible only FireFox has this issue and how can I solve this? 现在,这是我更新后的问题:只有FireFox才能解决此问题,怎么解决? Recall I'd rather not touch any of these existing scripts from the template unless it's necessary. 回想一下,除非有必要,否则我不要触摸模板中的所有现有脚本。

It turns out that the ExtJS scripts weren't minified correctly, which is why Firefox gave those errors. 事实证明,ExtJS脚本未正确缩小,这就是Firefox给出这些错误的原因。 Everything else was OK in my solution. 在我的解决方案中,其他一切都还可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM