I am creating a custom theme and I would like to know how to update the path of jQuery to use a CDN like the following:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

I don't want to use another module. I just want a simple way to change the path of the script.


Add the following code in the template.php file of your theme. (Replace mytheme with the actual short name of your theme.)

function mytheme_js_alter(&$javascript) {
  $javascript['misc/jquery.js']['type'] = 'external';
  $javascript['misc/jquery.js']['data'] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js';

As you are replacing the copy of the jQuery library with the same version copy hosted on Google, it doesn't make much sense to do it for just a theme. It would make sense to change it independently from the theme used from Drupal.

If you plan to use a different version of the library, you should first check there aren't incompatibilities with the jQuery version, and JavaScript code used from Drupal, or third-party modules. In case of incompatibilities, some JavaScript files used by Drupal could need to be replaced (using hook_js_alter()). That is what the jQuery Update module does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.