How to dynamically import a .js file into a .js file?

Duplicate question - see: How do you dynamically load a javascript file? (Think Cs #include)


Is there a javascript equivalent of @import? Because using the following method to include another javascript file from a javascript file does not look very nice and clean.

 document.write("<script type='text/javascript' src='something.js'></script>");

There is something on Google that looks like what I'm looking for, but it only works for their hosted files, and I don't know how these functions work internally (all of their code is compressed)

 google.load("maps", "2");

I need this because there are some javascript files that are sometimes only used in my application.

+3
source share

All Articles