需要潜在的竞争条件加载骨干和下划线

时间:2016-02-10 15:11:00

标签: javascript jquery backbone.js requirejs underscore.js

当使用requirejs从位于 /shared/common.js 文件中的require shim中定义的amazon s3中拉出主干和下划线时,下面的错误大约是1/10刷新。

backbone & underscore requirejs errors

下面的代码加载到 header.jade 文件中,以呈现标题中的主干视图,从localstorage中提取数据并确定用户的信息 然后将其加载到头DOM

script(type="text/javascript").
    require(['/shared/common.js'], function (common) {
      require(['/shared-marketplace/views/global-header-view.js', '/shared-marketplace/views/quote-form-modal-view.js'], function(GlobalHeaderView, QuoteFormModalView){
        var globalHeaderView = new GlobalHeaderView({el : $('header')});
        $('.open-quote-request').on('click', function(e){
          e.preventDefault();
          var phaseLoad = $(e.currentTarget).data('phase')
          quoteFormView = new QuoteFormModalView({'phase' : phaseLoad, 'fromNonProfilePage' : true}).$el.modal({show : true, backdrop: 'static'});
        });
      });  
    });

在主页js可以加载所有主干视图之前,页脚的代码也依赖于 /shared/common.js 加载

script.
require(['/shared/common.js'], function (common) {
  require(['main.js']);
  require(['/shared-marketplace/js/search-advisor.js'], function(){
    require(['/shared-marketplace/js/quote-form.js']);
  });
});

问题

  1. 两个需要调用 common.js 之间是否存在竞争条件导致上述错误,还是其他问题?
  2. 通过require加载具有相同依赖关系的文件(即 common.js )但在DOM上的多个位置的最佳方法是什么?

0 个答案:

没有答案