Search code examples
javascriptjquerydrupaldrupal-7

How to remove second library of jquery loading with Drupal installation


Question: Can someone tell me why a second version of jQuery appears to be loading with my Drupal installation? And how do I remove it?

Repro: If you view the source code of the NOVA home page you will notice 3 JS files in the header. The first one is jQuery 1.10.2 and the third one is jQuery v1.11.2.

Why: I want to optimize and consolidate the code as much as possible.

Details:

Link: http://119.9.25.149/

User: wpguest

Password: wpguest

I am running the jQuery update module if that makes a difference.(https://www.drupal.org/project/jquery_update)


Solution

  • The issue was Drupal 7 requires an older version of jQuery to run the core administrative modules and the website was using the jQuery Update module to bring the jQuery version to 1.10.2.

    To the fix the issue I had to use a Drupal hook in our public facing template file. This hook points the default jQuery to our preferred version. Code below:

    function TEMPLATE_NAME_js_alter(&$js)
    {
    $js['misc/jquery.js']['data'] = drupal_get_path('theme', 'TEMPLATE_NAME') . '/js/jquery.js';
    }
    

    After implementing the Drupal hook we removed the jQuery file we manually added on the template.php file and then disabled jQuery update leaving us with 1 jQuery library per page with alternative versions showing up for the public/administrative templates.