For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Monday, April 15, 2024

Add Dependent Scripts

 

 here is the code that allow to add dependent script :

 

 

    <script>
        const addDependentScripts = async function( scriptsToAdd ) {
        const s=document.createElement('script')
        for ( var i = 0; i < scriptsToAdd.length; i++ ) {
            let r = await fetch( scriptsToAdd[i] )
            s.text += await r.text()
        }
        document.querySelector('body').appendChild(s)
        }
         </script> 


Uses as below :

       <script>

    try {
        addDependentScripts( [
            "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js",
            "https://cdn.mywebshopapp.com/test/a1.js",
            "https://cdn.mywebshopapp.com/test/a2.js",
            "https://cdn.mywebshopapp.com/test/a3.js",
            "https://cdn.mywebshopapp.com/test/a4.js"
        ] );
        }
        catch (err) { }

       </script>

Share:

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip