English 中文(简体)
RequireJS - Loading an already loaded module
原标题:

I am trying to use RequireJS to load browser modules and I came into an interesting problem.

I have 3 modules named a, b and c having these simple source code:

a.js

define([ ./b ,  ./c ], function(c, b) {
 console.log( A IS LOADED! );

 return  A ;
});

b.js

define(function() {
 console.log( B IS LOADED! );

 return  B ;
});

c.js

define(function() {
 console.log( C IS LOADED! );

 return  C ;
});

When I load module a by itself, everything is working just fine, the following code runs and returns A :

require([ ./a ], function(a) { 
    console.log(a); //  A 
});

But if I need two different modules, which one of was already loaded:

require([ ./a ,  ./c ], function(a, c) { 
    console.log(a, c);
});

RequireJS will error:

C IS LOADED!
B IS LOADED!
require.js load timeout for modules: ./c 

when it s obviously already loaded.

Has anyone encountered this issue before? How can I solve it?

问题回答

According to the RequireJS website (http://requirejs.org/docs/errors.html#timeout) :

Likely causes and fixes:

  • There was a script error in one of the listed modules. If there is no script error in the browser s error console, and if you are using Firebug, try loading the page in another browser like Chrome or Safari. Sometimes script errors do not show up in Firebug.

  • The path configuration for a module is incorrect. Check the "Net" or "Network" tab in the browser s developer tools to see if there was a 404 for an URL that would map to the module name. Make sure the script file is in the right place. In some cases you may need to use the paths configuration to fix the URL resolution for the script.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签