Updating jQuery in Drupal the Right Way

I recently made a blog post about how to upgrade Drupal's jQuery version from 1.4.4 to 1.8. The problem is, popular contrib modules (views being the main culprit here) and even some core jQuery require an outdated version of jQuery (be 1.4.4, to be exact.). There is a module called jQuery Update, and it works well, but if you need a self contained theme (with no module dependancies) this might be helpful to you. In the last post, I didn't include details on how to use jQuery in noConflict mode, so I'll explain how it's done. As always, this is included in Base Building Blocks. I decided to add it by default after a number of complaints. (makes sense.)

The Good Stuff

I included a copy of jQuery 1.8 at the top of my html.tpl.php file before I load the Drupal scripts. I was going to use a page process function and use drupal_add_js, but I had trouble adding a weight that was less than the default version of jQuery.
window.jq8 = jQuery.noConflict();
Then you can use the updated version of jQuery like so:
(function ($) {
    //Your Code

What Sucks...

What really sucks is loading two copies of jQuery. If you have any other suggested method of doing this, please let me know! I'm always open to ideas. There is a jQuery update module that handles updating jQuery very well, I would suggest use of that. However when you are building a theme for someone that needs to work without dependancies, this is one way to go about it.


http://drupal.org/project/jqmulti was build for this exact use case. I didn't make it, but I use it

That module does the job, but I like to keep the theming stuff in the theming layer. :)

The problem with your way is that you have to modify each bootstrap which is bad because Bootstrap is Apache licensed and Drupal's repository is GPLv2 which are not compatible with each other.

57 kostenlos chat
Cam Chat Livecam 84

Gratis, XXX Chat, chat

The license is a bit irrelevant in the case of updating jQuery, as the Apache License allows the user of the software the freedom to use the software for any purpose, to distribute it, to modify it, and to distribute modified versions of the software. :) But there are problems putting that code up on drupal.org, which explains why BBB is in a git repo and not on drupal.org. :)

Yes as long it's not on Drupal.org but but afaics you do have it on d.o, http://drupal.org/node/1713614. No worries, I don't care, but the folks on d.o do. Personally I think it should be open to all kind off open source licenses, but thats not the case. And the positive thing about this, it's indirectly forces modules/themes to use Libraries API to include 3rd party libraries like Bootstrap which is good.

So if you could have implemented Bootstrap with Libraries API (http://drupal.org/project/libraries) that would have been awesome.

Yeah, I submitted it to d.o just to see what happened. I've considered adding Bootstrap as a library and making a branch of my theme for d.o that uses the bs library for drupal, but it's kind of bad design if you think about it... Drupal's themes need to be self contained. And how would you use the variables and mixins that Bootstrap has? I've been meaning to build a branch of BBB that uses the Bootstrap library, but I'm running short on time these days. If you would prefer it, feel free to fork, code, and contribute! I'll merge your stuff in gladly. :)

the hell, how is this "the right way"? ...

I'm quite open to suggestions and critique, but please explain yourself.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

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