Front & Back Development

Load Javascript source Dynamically

function loadJavaScriptOnDemand(src, callback) {
var script = document.createElement('script');
script.src = src;

script.onreadystatechange = function() {
if (script.readyState == 4 || script.readyState == "complete") {

if (typeof callback == "function") {
callback = null;

Above function you can call as following.

loadJavaScriptOnDemand(‘path/to/your/javascript’,function(){alert(‘JavaScript loaded’)});

Beto López
"Full stack" web developer focused in maintenance and bug fixing.Wordpress, Prestashop, HTML, CSS, Javascript, Php and Mysql. Also open source collaborator. Linkedin y Twitter.

We fix things, you rest easy
We fix websites. You rest easy. Ninjas get the job done. No excuses. No matter the problem, no matter the code, we’re here to help you.

Any doubts? Contact us
by Beto