简体   繁体   中英

Requirejs: module loading timeout

Actually I'm facing an irritating problem with Requirejs and Backbone. I'm developing my App on two different paths:

  1. the main access, for example: /App/index.php#list
  2. the sub access, for example: /App/index.php/clone#list

The problem appear when I need to load a module with the method require([module]).

If I use the absolute path, like require(['/App/js/views/modal.js']) I just obtain this error:

Error: Load timeout for modules: /App/js/views/modal.js

http://requirejs.org/docs/errors.html#timeout

If I use a relative way, like require(['js/views/modal.js']) on my main access and require(['../js/views/modal.js']) on my sub access, everything work as expected.

I'm loading other modules with the absolute path and they work, if I duplicate the module and require it with a different name it works, I tink the only difference is that the module I'm requiring has already been definited in another module and so it has already been loaded, like this:

Main module

require('/App/js/views/row.js'], function(Row){
     Somecode...
});

....

require('/App/js/views/modal.js'], function(Modal){
     Othercode...
});

Row Module

define([
'backbone',
'text!templates/row.html',
'views/modal', //the same view callend in my main file!
], function(Backbone, rowTemplate, Modal){
    Viewcode...
});

Modal Module

define([
'backbone',
'text!templates/modal.html',
'models/user_model',
], function(Backbone, modalTemplate, Model){
    Viewcode...
});

Maybe I'm missing something but I don't get the logic behind this, why isn't working with the absolute address?

You don't need to append .js on to the end of filenames in require.js, and I have seen odd behaviour in doing so myself. Also I'd advise you within the various modules of your application to use relative paths as it makes dragging and dropping modules / components of your app into another application more straightforward.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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