Currently you cannot overwrite (afaik) the url/path of jquery. It would be nice if we had an option to load it from Google's repository. Loading from Google's CDN it would probably be much faster and you can save bandwidth too.
We could extend this to swf object (modules that implement swf object) and jquery UI.

More reading on this:
http://code.google.com/apis/ajaxlibs/documentation/index.html
http://www.mkyong.com/jquery/how-to-load-ajax-libraries-from-google-code/

Comments

dave reid’s picture

Status: Active » Fixed

Actually it is possible. We have a hook_js_alter which is perfect for this scenario. All it would need is a small module to be coded for it.

andreiashu’s picture

yuhuu :) thanks Dave. so awesome!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Bevan’s picture

Status: Closed (fixed) » Active

Currently in D7 jquery and jquery UI can be loaded from Google only with a custom module or a not-yet-existent contrib module. Since most sites would benefit from using the google-served files (loads faster, already cached in browser for all sites that use it), I think this would be a great feature to include in core.

Since it's problematic for certain sites (on networks that can't access google) it needs to be a configurable option. Some would argue it should be off by default (though I would disagree). That is open for discussion, or a required question could be added to the installer forcing the installer to make an educated decision. Drupal could also try to guess whether to serve up google's or the server's jQuery by auto-detecting network connectivity.

More importantly though, is it too late to get this feature in Drupal 7 core?

dave reid’s picture

I think it would be too late in addition to the fact that since we can't control Google and their JS files, it's not going to be something appropriate for core. I've had a project idea for this in my sandbox for several months and after I'm done searching for duplicates, I'll publish a project page and link here when its done.

sun’s picture

Status: Active » Closed (won't fix)

This is a job for contrib. And we won't do marketing for Google in Drupal core. What about Yahoo's CDN? And Microsoft's? And my momma's?

mgifford’s picture

Issue tags: +jQuery, +google

I do love this community. :)

There are advantages though to centralizing javascript so that every individual site isn't loading these files, right? Caching is a good thing.

But definitely not in core. However, the flexible nature of Drupal makes it easy to bring in already (as was stated). I'm all for encouraging the broader use of this approach:

function openconcept_js_alter(&$javascript) {
  // Swap out jQuery to use an updated version of the library.
  $javascript['misc/jquery.js']['data'] = 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js';
  $javascript['misc/ui/jquery.ui.core.min.js']['data'] = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js';
}

I don't know that the api key is required, but it's easy to do it with that too http://code.google.com/apis/libraries/devguide.html

But you should be able to just stuff this in there if you want to:

    drupal_add_js('https://www.google.com/jsapi?key=INSERT-YOUR-KEY', 'external');

I'm also not wanting to re-open and this might be better placed in http://api.drupal.org/api/function/hook_js_alter/7

divThis’s picture

I have added this functionality, along with additional JS libraries offered via the Google Loader API in a new contrib module, Google Loader. Currently, it is Drupal 6 only, but should be easily ported to Drupal 7.

mgifford’s picture

This is also an option in http://drupal.org/project/jquery_update as it turns out.

I didn't realize that it was largely backward compatible when I posted this.