Pages

Thursday 20 December 2012

Use CDN jQuery for your Drupal theme


Simple code to use jQuery from Google CDN. Change the version "1.8.0" to your preferred version.
You can also switch to use Microsoft CDN, or other sources by changing the jQuery path below.
/**
* 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.8.0/jquery.min.js';
    $js['misc/jquery.js']['data'] = $jquery_path;
    $js['misc/jquery.js']['version'] = '1.8.0';
    $js['misc/jquery.js']['type'] = 'external';
  }
}
This code may conflict with jQuery Update module.

No comments:

Post a Comment