UPDATE: I think the best answer is here: Lazy loading in node.js
MY INITIAL COMMENTS: Well, it's a matter of practice, some guys like it upstairs, and some are lazy. In my opinion, both of them are good and should be used as needed, so I think that the author is here, because loading an entire bundle library at startup will overload the module for the most part that is never used, and therefore increase loading time. Although loading libraries on demand is a synchronous operation, but if we look at the help
method as an object, this will give the effect of loading an asynchronous module (see AMD , which is a popular template).
False loading is also a good choice if you need to choose between loading libraries in a particular case, for example,
var isOSX; // some code here which finds if this is OSX // then this if (isOSX === true) { var platformHelper = require('supercoolosxhelper'); } else { var platformHelper = require('yetanothercoolhelper'); }
In short, you should anticipate in your code if the probability of using the method is high or even average, then you must demand from above, otherwise, if it is low, it would be nice if the required
on module needs a framework.
source share