Friday, January 28, 2011

Import JavaScript file from within JavaScript synchroniously?

Programmer Question

Instead of messing up my HTML file, I'd like to import my external JavaScript files through another JavaScript file, much like @import in css.



On several websites, including StackOverflow itself, I noticed that appending a script tag to the DOM can solve this issue; however, this is done asynchroniuosly, while the order of my files is important - the second file for example may rely on the first file in the list. When, say, loading jQuery first and then loading a dependency (plugin etc.) of it, the dependency might finish loading earlier and will throw errors because jQuery doesn't exist yet.



Therefore, this does not seem to be an option. How can I synchroniously load JavaScript files from within another JavaScript file?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails