Async Load JavaScript Files with Callback

前端 未结 6 1318
礼貌的吻别
礼貌的吻别 2020-12-05 08:26

I am trying to write an ultra simple solution to load a bunch of JS files asynchronously. I have the following script below so far. However the callback is sometimes called

6条回答
  •  旧时难觅i
    2020-12-05 08:54

    I recommend you use a tiny loader javascript like JcorsLoader (only 647B with Gzip)

    JcorsLoader.load(
                    "http://xxxx/jquery.min.js",
                    function() {
                        $("#demo").html("jQuery Loaded");
                    },
                    "http://xxxx/jquery.cookie.js",
                    function() {  
                        $.cookie('not_existing'); 
                    }
                );
    

    Load multiples js in parallel and execute in order without blocking DOMReady or onload.

    https://github.com/pablomoretti/jcors-loader

提交回复
热议问题