ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

External Javascript libraries importing

custom_script

#1

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


Select many options from drop down
#2

Some suggestions to make me correct ??


#3

To continue from this Adding javascript and css libraries for a doctype using custom script

This may help https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/What_is_JavaScript

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 https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events


#4

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


#5

try this:

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