Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function to check if jquery plugins are already initialized

i want to check if jquery plugins are already initialized / included (prevent dublicate resource loading) and if not i want to add the plugin by CDN or by a local source.

Anyone can help me with that Problem?


Update:

I'm currently building a custom template in drupal. In that template i'm using a slick slider for scrolling through pictures in a content gallery. I also want to use a custom module for a slideshow, which uses the slick slider too (js, css integrated in the module). So now i want to check if the slick slider of the slideshow module is already initialized, if not i want to load the slick slider js via cdn.

Hope that helps for understanding my problem.


Update 2: Resolved the problem by using php and drupal core functions. I also found a solution with the modernizr.js load function -> asynchronous loading.

like image 238
themca Avatar asked Dec 05 '25 04:12

themca


2 Answers

You can check and detect the plugin using this

if(jQuery().pluginName) {
    //run plugin
}
like image 156
Fatkhan Fauzi Avatar answered Dec 07 '25 18:12

Fatkhan Fauzi


You can try this:

if (!jQuery.fn.plugin) {
    jQuery.getScript('http://url/to/the/script');
}
like image 35
jcubic Avatar answered Dec 07 '25 16:12

jcubic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!