【问题标题】:Load timeout for modules in Internet ExplorerInternet Explorer 中模块的加载超时
【发布时间】:2012-07-26 21:10:32
【问题描述】:

此问题仅出现在 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 中什么都没有出现,一切正常。

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

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

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

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

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

感谢您的帮助。

【问题讨论】:

    标签: javascript internet-explorer module cross-browser requirejs


    【解决方案1】:

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

    订单插件最好与传统脚本一起使用。它不是 需要使用 define() 来定义模块的脚本。有可能的 混搭“订单!”具有常规依赖项的依赖项,但是 只有“命令!”将按相对顺序评估每个 其他。

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

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

    【讨论】:

    • 谢谢,我会尝试并随时通知您。
    • 无法告诉你进展如何,我在 RequireJS 2.0 中遇到了多个错误,这对初学者来说有点困难。我一直在努力。
    • 谢谢,我终于成功了(在另一篇文章的帮助下),它使用 RequireJS 2.0 和 shim 配置解决了 Internet Explorer 上的问题。
    • 嗨@Brut4lity 你有帖子的链接吗?使它工作的垫片配置是什么?谢谢
    猜你喜欢
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 2013-08-27
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多