javascript - Internet Explorer 中模块的加载超时

标签 javascript internet-explorer module cross-browser requirejs

此问题仅出现在 Internet Explorer 9 中,适用于 Chrome 和 Firefox。

这是我的主文件,它加载了我所有的依赖项:

// Filename: main.js

// Require.js allows us to configure shortcut alias
// There usage will become more apparent futher along in the tutorial.
require.config({
    paths: {
        jQuery: 'libs/jquery/jquery',
        Underscore: 'libs/underscore/underscore',
        Backbone: 'libs/backbone/backbone',
        JSON: 'libs/json2/json2',
        templates: '../templates'
    }

});

require([
    // Load our app module and pass it to our definition function
    'order!app',

    // Some plugins have to be loaded in order due to there non AMD compliance
    // Because these scripts are not "modules" they do not pass any values to the definition function below
    'order!libs/jquery/jquery-min',
    'order!libs/underscore/underscore-min',
    'order!libs/backbone/backbone-min',
    'order!libs/json2/json2-src'
], function(App){
    // The "app" dependency is passed in as "App"
    // Again, the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function
    App.initialize();
});

这是浏览器崩溃的地方:

SomeRoute:function(){
    facade.console.log("SomeRoute");
    $("#toDelete").remove();
    this.user =  new User($.cookies.get('User'));
    var that = this;
    require(['views/SomeView'],function(SomeView){    // On this require
        if(that.user.get('usr_id') > 0){
            var view = new SomeView();
            $("#domelement").append(that.changeView(view));
        }
        else window.location = APP_URL + "/login#login";
    });
}

当我走这条路时,我得到这个错误:

SCRIPT5022: Load timeout for modules: views/SomeView 
http://requirejs.org/docs/errors.html#timeout 
require.js, Line 27 Char 311

但在 Chrome 或 Firefox 中什么也没有出现,一切正常。

编辑:此外,刷新我要求加载的页面非常好。只有在我走路线的时候。我必须刷新才能访问我的其他模块内容。

编辑 2:经过一些附加测试后,我尝试将“enforceDefine: true”添加到我的 main.js 并更改了我的 require 调用。没有改变。 此外,使用此函数调用的任何 View ...

        confirmView: function(idDialog, view, opts1){
            facade.loader("body");
            require(["text!templates/common/dialog/confirm.phtml"], function(dialogTp){
                var opts = $.extend({}, facade.dialog.defaultOpts, opts1);
                // Delete previous dialog with same ID
                $("#"+idDialog).remove();

                // select the view we'll set
                var el = "#"+idDialog+" .modal-body";

                // Create our template with our options
                var contentDialog = _.template(dialogTp, { "option": opts, "text": "", "id": idDialog});
                $("body").append(contentDialog);

                require([view], function(viewClasse){
                    viewClasse.setElement("#"+idDialog+" .modal-body");
                    opts.preLoad(viewClasse);
                    viewClasse.render();

                    facade.unloader("body");

                    // twitter modal instance
                    facade.dialog.events(idDialog, opts, viewClasse);
                    $("#"+idDialog).modal(opts.modal);
                });
            });
        }

...也会崩溃(超时)。

我真的不知道发生了什么......

感谢您的帮助。

最佳答案

我以前遇到过这个问题,它源于尝试将 order 与普通模块一起使用,而不是脚本。来自旧的 1.0.x 文档:

The order plugin is best used with traditional scripts. It is not needed for scripts that use define() to define modules. It is possible to mix and match "order!" dependencies with regular dependencies, but only the "order!" ones will be evaluated in relative order to each other.

http://requirejs.org/docs/1.0/docs/api.html#order

无论如何,您应该使用 RequireJS 2.0,它取消了订单插件 in favour of the shim configuration .

关于javascript - Internet Explorer 中模块的加载超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612370/

相关文章:

蟒轮 : "ModuleNotFoundError" after installing package

c# - 可以在虚方法中抛出 NotImplemented 异常吗?

javascript - Sencha Touch 中是否有声明全局变量的选项

javascript - 如何从数据库中解析json格式的数据

c++ - 错误 LNK2001 : unresolved external symbol CATID_AppContainerCompatible

jquery - 我的 jQuery 代码无法在 IE 中运行

javascript - 通过 Javascript 将值传递给 Controller 返回 View MVC3 Razor

javascript - Onsubmit 事件不为 null,而 JavaScript 对象说它为 null?

javascript - TinyMCE,IE9,剥离 <script> 标签

perl - 无法安装任何 perl 模块,因为它无法定位 strict.pm