Load Script after 10 seconds

Nitish Kumar Singh
Nitish Kumar Singh
Clock Image 1 minutes
Posted on
March 13, 2020

Load Script after 10 seconds


function loadJavaScriptDynamically(url){
    // Create the Script Tag
    var dynamicScript = document.createElement('script');
    
    // Set the script url, from where you have to load the js
    dynamicScript.src = url;

    // By default dynamic script a async in nature but I don't want this now
    // If you want the then can for this async strategy  
    dynamicScript.async = false;

    // Now lets append this script in our head tag.
    document.head.appendChild(scriptTag);
};

// After loading the webpage and 10 second has been gone, this script will be loaded
setTimeout(function(){
    loadJavaScriptDynamically(url , parentNode);
},10000);


// After loading the webpage and 4 second has been gone, this script will be loaded
setTimeout(function(){
    loadJavaScriptDynamically(url , parentNode);
},4000);

Last updated at Friday, Apr 24, 2020 by Nitish Kumar Singh
comments powered by Disqus

Subscribe to our Newsletter

Tweet this article Tweet this article