Using a different jQuery version on your Drupal front-end & back-end

Using the Drupal 7 'jQuery Update' module you are able to upgrade your default jQuery version. At times you may want to set a different jQuery version to be used on the Frontend & Backend, for instance if you are wanting to use a sazzy jQuery gallery viewer. If you update your version of jQuery to above 1.8.x I've noticed there are issues when it comes to the back-end admin pages. In this scenario you can set a different version to be used on the Frontend & Backend with jQuery Update module (not something you could do when I originally wrote this post).

That should solve most needs, but there is still the case that jQuery Update module might not offer the version you want to use - for example 1.11.0 (at the time of updating this post).

You don't want to change your entire jQuery version, as you will run into problems when using the Drupal admin interface. It is possible to run two versions of jQuery, but that will just degrade your sites performance for visitors.

Provided you use a different theme for your front-end & back-end (something I always do), this technique will let you use a newer version of jQuery on your front-end,  while still keeping the compatible, older versions on the back-end (ie when editing in /admin).

Add this hook_js_alter code to your front-end themes template.php file. It will replace the default jQuery version with the one of your choice.

	function hook_js_alter(&$javascript) {
	  // Swap out jQuery to use an updated version of the library.
	  $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';
Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +10 years.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.