1

I have added following module via Require.JS. Everything works fine But I want to know how to load them without using multiple require statement in the same order mentioned below.

<script type="text/javascript">
require(['common'],function()
{  require(['jquery','fastclick','nprogress','charts','underscore','spinner'],function()
  {
    require(['firstDashboardController']);
  }); 
});
</script>

1 Answer 1

1

Write your firstDashboardController as a proper AMD module, with dependencies:

define(['jquery','fastclick','nprogress','charts','underscore','spinner'], ...

This will guarantee that everything listed in your dependencies will load first.

People typically put RequireJS configuration in their common module. I recommend against loading configuration as a module. It is preferable to just load with with a script element, just after you load RequireJS itself. This way you are sure that the configuration is always loaded when you need it. Otherwise, you have to play rigmaroles with nested require calls like you show in your question.

If you do all of the above, then you can just do:

require(['firstDashboardController']);

when you need it, without having to nest require calls.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.