js include



after seeing that it was possible to write a js include (since it's not in the language), I decided to write my own. this one uses an id attribute to base things on and uses onload (only works for IE11 and up). all js listed in following args after the id are added after the script tag that contains the id you chose. it uses the Node.insertBefore() and document.createElement() and Node.setAttribute() - the results show up the the debugger and also on the page. apparently, asynchronously loaded js doesn't work with document.write(); (kind of annoying anyway since it makes pages disappear). I had hoped I could have full functionality, but I guess I can't.

js_include_after(id,counter_start) takes 2 arguments initially, the id to base everything off of (the script that includes js-include.js), and the counter starting number such as 1 to append to the id's of the scripts that get asynchronously inserted.

the rest of the arguments can be either strings which are the script filenames, or new Array('abc.js','def.js') of strings or a string that is split like "abc.js,def.js".split(',') which contain the js filenames to include.

you should open the debugger to see the logging this example app creates to see if it gets the order right.

I finally got it to work consistently.


Numbers 1..4 should be in order: