08 April

Avoiding Javascript conflicts in Magento


One big subject that comes up when moving our Magento project to a production environment is the way to combine the javascript files. Most developers work with jQuery instead of working with Prototype (js library that is included with Magento), this always brings a lot of headaches when combining both type of files and generates conflicts like  undefined errors, jQuery warnings, etc.

Error Magento javascript



The solution for this would be to combine Prototype files in one side, and Jquery files in another file, this will avoid errors and we’ll also have all javascript files combined in only 2 files.

Considering we’re adding js files through XML, the practice is very simple, just add the attribute <group> like this:

Now, if we merge the js files through our Admin-panel in: System->Configuration->Developer->Javascript files->Merge JavaScript Files = Yes   we’ll get something like this:







Finally we get all javascript files combined in 2 different files, so that both libraries never cause any conflict.

It helped?…so i’m happy! ;)






Back to Top