function lazyload() { var scriptTag = document.createElement('script'); scriptTag.src = "//my_example.js"; // set the src attribute scriptTag.type = 'text/javascript'; // if you have an HTML5 website you may want to comment this line out scriptTag.async = true; // the HTML5 async attribute var headTag = document.getElementsByTagName('head')[0]; headTag.appendChild(scriptTag); }