In order to add dynamically a script to your page you can use the DOM and access the header, in this way you can be sure that the page will contain this file before other script will be executed.
var currentFile = 'test';
var headID = document.getElementsByTagName("head")[0];
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = 'js/' + currentFile + '.js';
headID.appendChild( script );


