Search code examples
requirejsjs-amd

How does AMD (specifically RequireJs) handle dependancies across multiple modules


I have my main initialization script which calls require() and one of the dependencies is a utilities framework, but some of the other modules that I'm specifying via require() also themselves have defined this framework as a dependency.

For example (init.js):

require(['module-a', 'module-b', 'module-c'], function(a, b, c){
    // where module-c is the framework
});

And then in 'module-a' I have:

define(['module-c'], function(c){
    // utilize module-c framework
});

So how does AMD/RequireJs handle this scenario, does it load the same framework twice?

Any help appreciated.

Kind regards, Mark


Solution

  • It will only be loaded once, both of the above modules will get the same module value for 'module-c'.