Just wondering about this…
I have several separate javascript files, that all contain code based on the module pattern. A few of the modules have some of the others as dependencies. If i know that none of the code would be called on the HTML until the page is loaded, does the order in which the files load still important?
Is the fact that the module code sits inside an immediate function enough to trigger the requirement that the other modules be loaded already?
I am prepared to look into the RequireJS library if need be, but just wanted to know if what i am going is ok first.
If possible set up your dependencies so you can load and set up all your modules when the javascript file gets loaded (i.e. use a self executing function).
And then call a
.initor equivalent function on all your modules in a.readyblock. That way you can explicitly call any functionality requiring dependencies after all your files have loaded.An example:
Any code that doesnt have dependancies can be executed in the closures of
foo.js&bar.jsand any dependant code can be called through yourinitfunction on.readyonce all the files have loaded.