If possible, configure your dependencies so that you can load and configure all your modules when loading a javascript file (i.e. use the self-launch function).
And then call .init or the equivalent function for all of your modules in the .ready block. Thus, you can explicitly call any functionality that requires dependency after loading all of your files.
Example:
foo.js (function() { function initFoo() { ... } ... window.namespace.foo = { init: initFoo } }()); bar.js (function() { function initBar() { ... } ... window.namespace.bar = { bar: initBar } }()); main.js (function() { $.ready(function() { window.namespace.foo.init(); window.namespace.bar.bar();
Any code that has no dependencies can be executed in closing foo.js and bar.js , and any dependent code can be called through your init function on .ready after loading all the files.
Raynos
source share