What to do if several Magento extensions include the jQuery library

I read a guide on how to enable jquery in magento correctly

  • enable library
  • enable conflict script
  • go to $ jquery call and change it to jQuery

It is very simple with one extension. However, in my case, I installed 3 different extensions, and they all want to enable jQuery. Of course, I do not want to duplicate this library and name it 3 times. Firstly, I think that I can simply manually enable the jquery library in the very first line of the <head> and remove all jQuery inclusion in 3 extensions. But this will not work, usually only one of them works. If I allow all 3 extensions to include jquery, then all of them work. How can I do all jquery extensions in the store, while only including libray once?

Someone suggested that I should include all jquery dependent scripts at the top of the <head> , right? However, the problem is that I do not know how to organize scripts in Magento with the addJs or addItem . There are no parameters, either before or after, as in <block> ?

+6
source share
1 answer

If you want to force the Javascript load order included in the addJs method, the easiest way is to specify a name using the <params> , for example:

 <action method="addJs"> <!-- Loads second --> <script>vendor/jquery-1.6.2.min.js</script> <params><![CDATA[name="jquery2"]]></params> </action> <action method="addJs"> <!-- Loads first --> <script>vendor/jquery-1.8.2.min.js</script> <params><![CDATA[name="jquery1"]]></params> </action> 

Magento will download Javascript files in ascending order in alphabetical order based on the specified name.

In your case, however, it would be more useful to find out why extensions and various jQuery files do not play with each other.

  • Does each extension support a specific version of jQuery?
  • Do they use different noconflict methods (i.e. use a direct call to jQuery.noConflict() , and the other use something like var $j = jQuery.noConflict() )?
  • Do they all use the same global variable names?
+3
source

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


All Articles