How can I avoid loading jQuery scripts multiple times?

On my site, I load a jQuery UI script using the following code:

wp_enqueue_script('nf-jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js')

In my plugin, I use the following code:

wp_enqueue_script('wp_filebrowser-jqueryui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js')

As a result, both of these lines are added to my header - and loading the script twice is not very good.

Yes, I know that I can remove it from my plugin or my site. But the fact is, everyone can download my plugin, and they can already load the jQuery UI script.

How can I avoid adding a script?

+3
source share
3 answers

This stack overflow message may be useful in how to check if jQuery user interface has been loaded -

+2

script, ...

wp_deregister_script ('nf-jquery-ui');

enqueue_script...

wp_enqueue_script ( 'wp_filebrowser-jqueryui',...

jQuery , .

+2

WP API . , , script ( ).

jQuery jQuery UI, , , . jQuery, jQuery-ui. , wp_- jQuery script, / wp.

0
source

Source: https://habr.com/ru/post/1770021/


All Articles