External Javascript libraries importing

In version 10, when I had to use any external library, I used it as:

$.getScript("url of cmd",function(){
});

And that library was accessible throughout the code. But same is not happening in v11. I had to reinitialise the cdn and that too in a way that the code should be within the cdn’s function like this :

$.getScript("url of cmd",function(){

//my code here

});

Is there any other way for v11 to use cdn libraries as sometimes its frustrating that if you want to use any library let say select2 at two places, then you had to call that 2 times. Just need to know a permanarn solution to initialise library once and use throughout.

Thanks in advance

Some suggestions to make me correct ??

To continue from this Adding javascript and css libraries for a doctype using custom script - #15 by hari.kishor

This may help What is JavaScript? - Learn web development | MDN

In particular these sections:
What is JavaScript doing on your page?
Script loading strategies

That tutorial should help - for eg you may need to listen for the “DOMContentLoaded” event?

Here’s an intro to events Introduction to events - Learn web development | MDN

I can see in console that those libraries are loaded if initialised on start in custom script but doesn’t gets called if my code needs that library after some other block of codes. Happening in v11, but was running perfect in v10

try this:

$.getScript(“url of cmd”).done(function(){
//ur code
});

2 Likes