Use CDN jQuery for your Drupal theme

Simple code to use jQuery from Google CDN. Change the version "1.7.1" to your preferred version.
You can also switch to use Microsoft CDN, or other sources by changing the jQuery path below.

1
2
3
4
5
6
7
8
9
10
/**
 * Implements hook_js_alter().
 */
function YOUR_THEME_js_alter(&$js) {
  if (isset($js['misc/jquery.js'])) {
    $jquery_path = 'http:// ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
    $js['misc/jquery.js']['data'] = $jquery_path;
    $js['misc/jquery.js']['version'] = '1.7.1';
  }
}

PS: Remember to remove the white space after "http://" in the code above as it conflicts with my text formatting here.

This code may conflict with jQuery Update module.