Here's a simple example...
base page includes first script file
~~~~~~~~~~
first script file is like
// first.js
// whatever script steps are specific to this js file
// additionally:
function includeJsFiles() {
var otherScripts = [
'second.js',
'third.js'
]
var head = document.getElementsByTagName( 'HEAD' )[0];
var last = otherScripts.length;
for (var i = 0; i < last; i++) {
var script = document.createElement( 'SCRIPT' );
script.src = otherScripts[ i ];
head.appendChild( script );
}
}
window.onload = includeJsFiles;
~~~~~~~~~~
second script file for demo
// second.js
alert('second JS file included by first');
~~~~~~~~~~
third script file for demo
// third.js
alert('third JS file included by first');
This can be extended indefinitely by adding more filenames to the {includeJsFiles} array in the first.js.
By the way, on a tangential note, you can dynamically include external HTML, text, etc., by using the XMLHttpRequest object to mediate the process (what we so cavalierly call "AJAX"), so long as the external content is in the same domain of origin as the base page. Probably a question for another day.