Changing jQuery Version in Magento 1.9.3.4
As a new developer working with Magento 1.9.3.4, you might find yourself needing to upgrade the version of jQuery for an extension that requires a newer version such as >1.8. This guide will walk you through the necessary steps to accomplish this task.
Understanding the Current State
Before we begin, let’s first identify your current jQuery version in Magento 1.9.3.4:
- Open Firefox or Chrome.
- Navigate to your Magento storefront.
- Right-click and select “Inspect Element” or press F12.
- Go to the “Console” tab.
You will see something like:
jQuery is not defined
This indicates that jQuery has been loaded, but it’s likely version 1.7.2, which is the default in Magento 1.x versions.
Step-by-Step Guide: Upgrading jQuery
1. Download and Extract the New Library
Download a compatible jQuery library from http://jquery.com/download/. For this example, let’s use v1.9.1 as it’s the latest stable release that works with Magento’s dependencies.
Extract the downloaded zip file to a folder outside your Magento installation.
2. Upload jQuery Files to Your Server
Using an FTP client like FileZilla or the built-in File Manager in your hosting control panel:
- Connect to your server.
- Navigate to the root directory of your Magento site (usually
/public_html/magento). - Inside this folder, create a new subfolder named
js. - Upload the extracted jQuery library from step 1 into the
/jsfolder.
Your file structure should look like:
magento/
â
âââ js/
â âââ jquery-1.9.1.js
â
âââ index.php
3. Update Magento’s Core Files
Open your favorite text editor (like Sublime Text or Atom) and locate the following files:
-
/app/design/frontend/base/default/template/page/html/head.phtml -
/lib/Varien/JavaScript/Emulate.js -
/lib/Localise/En.php
Make sure to backup these files before editing, as we’ll be modifying them.
4. Editing the Files
head.phtml: Locate this line:
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/prototype/prototype.js') ?>"></script>
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/lib/ccard.js') ?>"></script>
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/lib/ccform.js') ?>"></script>
Replace it with:
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/prototype/prototype.js') ?>"></script>
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/lib/ccard.js') ?>"></script>
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/lib/ccform.js') ?>"></script>
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/jquery-1.9.1.js') ?>"></script>
We’re simply adding our new jQuery library at the end.
Emulate.js: Find this line:
var $j = jQuery.noConflict();
$j(document).ready(function($){
Remove the $j function and replace it with:
var jQuery = $.noConflict();
jQuery(document).ready(function($){
This tells Magento to use $.noConflict() to prevent conflicts between jQuery (which we’ll call $) and other libraries like Prototype.
En.php: No changes are needed in this file for our purposes.
5. Flush Magento Cache
- Log into your Magento admin panel.
- Navigate to “System” > “Cache Management”.
- Under the “Actions” column, select “Flush Magento Cache”.
Verifying the Upgrade
Reload your storefront and inspect the page as described in the first section.
You should now see:
jQuery is defined
This confirms that jQuery has been successfully upgraded to version 1.9.1.
Conclusion
Upgrading the jQuery library in Magento requires a careful approach due to potential conflicts with other scripts. By following this guide and understanding the core files involved, you can ensure a successful upgrade without breaking your store’s functionality.
Remember that while this solution works for Magento 1.x versions, it is highly recommended to consider upgrading to the latest version or migrating to a platform like Laravel Company (https://laravelcompany.com/blog/magento-migration-guide) which offers more stability and better performance.
Happy coding!