1

I started developing a theme for Magento 2.2.0 and now I have to use some external javascript libraries both in my theme and my modules.

So what is the best solution to prevent loading the same library twice?

Should I create a new Module containing my javascript libraries and refernce them in my other modules?

EDIT:

For example I have a Module which requires a specific library like swiper.js. So I would require it somehow with My_Module/path/to/swiper.js. But if I have another Module with the same dependency My_Module2/path/to/swiper.js it now is loaded twice?

In Magento2 I can require jquery and any other core library from anywhere but the documentation says you shouldnt put js into mageroot/lib/web/js.

  • Can you explain more about the issue So what is the best solution to prevent loading the same library twice?? – Khoa TruongDinh Oct 14 '17 at 1:11
0

You should not have to worry about that. Magento 2 and Require JS are made so that they merge the individual require files and create one large file before the includes are taking place.

More info here: http://inchoo.net/magento-2/javascript-bundling-magento-2/

  • Ive read that glob post, but what happens if for example you have Vendor_Module1/js/my-lib.js and Vendor_Module2/js/my-lib.js? Isnt it then still included twice? – Code Spirit Oct 17 '17 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.