Reputation: 854
Suppose there are three modules: m1, m2, m3
Where mi(i=1..3) is empty module:
define(function() {
return this;
})
And exists additional module useAll that depends on m1, m2, m3 modules.
What is the difference between two implementations of useAll module:
All modules on which depends useAll mentioned in define()
define(['m1', 'm2', 'm3'], function() {...})
Modules mentioned in require() function
define(function () { require(['m1']); require(['m2']); require(['m3']); ... })
Is there any issues with script loading time and order?
Upvotes: 0
Views: 172
Reputation:
The diferrence is that in the second implementation your
require
are treated by r.js
as nested dependencies and
by default they will not get included in optimization process,
unless you specify:
findNestedDependencies : true
From the docs:
Finds require() dependencies inside a require() or define call. By default this value is false, because those resources should be considered dynamic/runtime calls. However, for some optimization scenarios, it is desirable to include them in the build.
Another difference, is that the second implementation can load CommonJs modules too.
If you use require
to define your module, you cannot return any value as a result of execution. This means, that you cannot use this module as a real dependency to another module
Upvotes: 3