Splitting the configuration - resoai/TileBoard GitHub Wiki

The CONFIG variable can become somewhat unyieldy pretty soon. If you encounter this, it might be a good idea to split up your config.js for better readability. If you decide to do so, you can use the following function to load any JavaScript file at any place in your config.js:

function loadJS(url) {
   var xhttp = new XMLHttpRequest();
   var script = document.createElement( "script" );
   xhttp.open("GET", url+suffix, false);
   xhttp.send();
   script.text = xhttp.responseText;
   document.head.appendChild( script ).parentNode.removeChild( script );
}

It can be used like this:

loadJS('templates.js'); //defines var TEMPLATES
alert(TEMPLATES);