Load JavaScript as They Are Needed

Work with jQuery.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if ($('div').hasClass('popcontainer')) {
$.getScript('https://pages.shino.cc/cdn/js/botui/botui.js', function () {
bot_ui_ini(); // do something when load successfully
});

/* or multiple load */
$.when(
$.getScript( "https://cdn.jsdelivr.net/vue/latest/vue.min.js" ),
$.getScript( "https://unpkg.com/botui/build/botui.min.js" ),
$.getScript( "https://2heng.xin/botui.js" ),
$.Deferred(function( deferred ){
$( deferred.resolve );
})
).done(function(){
bot_ui_ini();
});
}