Last Updated: February 25, 2016
·
857
· matt6805

Write script tags to the document head

Here's a quick function that I've used lots of times to write script tags to the head of a document without the use of libraries:

function appendScriptTag(path) {
var head = document.getElementsByTagName('head')[0],
    script = document.createElement('script');
script.type = 'text/javascript';
script.src = path;
head.appendChild(script);
}