Google AJAX Libraries API Plugin
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Update: I have updated this plugin to version 0.9.
Earlier this week Google announced their Ajax Libraries API.
The AJAX Libraries API takes the pain out of developing mashups in JavaScript while using a collection of libraries. We take the pain out of hosting the libraries, correctly setting cache headers, staying up to date with the most recent bug fixes, etc.
The Google Ajax Libraries API Plugin (what a mouthfull) is designed to make it easy to use the Google hosted libraries without the need to mess with your theme and plugin code.
When activated, the plugin will “listen” to all of the scripts added (via the WordPress wp_enqueue_script function) to your pages header and automagically switch the locally hosted library to a Google hosted one. Deactivating the plugin will remove the “listener” and your site will return to using the local versions.
WordPress MU administrators should copy the plugin into their MU-Plugins directory for it to be enabled across all of your hosted blogs.
The latest version of this plugin is available for download below.

May 30th, 2008 at 12:31 am
Hello, it is a great plugin!! But it seems a problem with jquery and prototype conflicting.
I wrote a patch for it, please refer my blog (sorry , it was written in chinese).
May 30th, 2008 at 1:52 pm
@TaopaiC: Thanks for the message. I haven’t had a problem with jquery and prototype on the sites I’m using it on as yet - but I will have a look at your solution with a view to integrating it.
May 31st, 2008 at 10:09 am
so quick~~
thanks~~
May 31st, 2008 at 4:53 pm
B,
This is a great idea.
When I got the annoucnement about Google’s API two days ago I manually commented out my existing jQuery in favor of Google’s “new way”.
Can I ask you… let’s say I uncommented MY local jquery reference… AND have your plugin working. How does your plugin tell WordPress (or my browser) not to pay attention to my local jQuery reference? Do they have to be named exactly the same? (because I always name my local latest version to “jquery-latest.js” so that I don’t have to change my theme template whenever I want to throw up the latest jQuery version).
May 31st, 2008 at 6:16 pm
@Steve: The plugin hooks into the interface used by wp_enqueue_script, so with jQuery for example, if any themes or plugins enqueue jQuery, the library (jquery.js) is replaced when output by the Google library (jquery-min.js). Any libraries that are hardcoded into themes or plugins are ignored.
May 31st, 2008 at 7:27 pm
Oh, so if previously my “header.php” file was adding jQuery with a simple [script src='path/jquery.js'][/script] that wouldn’t matter one way or the other?
Perhaps I’m enqueue ignorant.
I’ll have to look it up.
May 31st, 2008 at 11:56 pm
Hi Barry,
Coincidentally I also wrote and released a Google AJAX Libraries API plugin for WordPress but I’ve chosen to use the wp_print_scripts action hook instead of filtering the script_loader_src . Check out my Google AJAX Libraries API WordPress plugin.
June 3rd, 2008 at 2:46 pm
@TaopaiC: I’ve updated the plugin to handle the loading of jQuery and Prototype on the same page. I’ve incorporated part of your solution, but have removed the need for an extra javascript file containing the noconflict code. Have a look and let me know what you think.
June 4th, 2008 at 1:38 am
It works good.
thanks Barry
June 7th, 2008 at 6:57 am
Getting this little bummer (x4) at the top of my admin pages after activating the plugin:
Warning: preg_match() [function.preg-match]: Compilation failed: unrecognized character after (?< at offset 3 in /var/www/vhosts/thefightchannel.com/httpdocs/wp-content/plugins/usegooglelibrary.php on line 26
Thoughts?
June 8th, 2008 at 8:32 pm
effects.js can be loaded from Google too…
“/effects.js” => “http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/effects.js”
June 9th, 2008 at 2:24 pm
@James D Kirk: What version of php are you using? The latest version of the plugin uses the named subpattern functionality of preg_match which may not be in early versions. if you can confirm the version you are using - then I’ll write a short workaround for it.
June 10th, 2008 at 1:47 pm
I’m getting the same error as James D Kirk, and I have PHP 5.
June 10th, 2008 at 2:32 pm
@Jordan & James D Kirk: I have updated the plugin to version 0.7 and removed the named subpattern from the regular expression check. Fingers crossed this should get rid of the problem you have been having.
June 10th, 2008 at 6:38 pm
Hey Barry. Apologies, yes, like Jordan I am running php5. And the 0.7 release does seem to make those errors go away.
New question, however, is how do we “know” your plugin is actually working? What can I check or is there code I can view to see that in fact I am pulling code from the libraries? Curious. Thanks!
June 11th, 2008 at 2:25 pm
@James D Kirk: The easiest way is if you have Firebug installed with the Firefox browser. Have the Net tab visible when you load your page and it will show which locations it loads each part of your page from. Alternatively just look at the source of your page and check for javascript includes from Google for the jQuery and other libraries
June 13th, 2008 at 1:02 am
Can this plugin also be used in theme files to pull in the requested javascript library if requested? The way I understand this plugin is that it adds the latest js library to your Wordpress install, not your theme files. Is this correct? If so, is there a call that I can make in my header to pull in the latest scripts into the head of my site?
June 13th, 2008 at 2:27 pm
@Thad: In your theme, rather than including the loading of the javascript library in your theme header.php file, add something along the lines of the following to your themes functions.php file:
if(function_exists(’wp_enqueue_script’)) {
wp_enqueue_script(’jquery’);
}
This will then load the jQuery library for your theme in a manner that will make changeable to the google libraries by the plugin.
June 27th, 2008 at 6:04 pm
The google ajax plugin is now at version 0.8. If you are using version 0.7 and DO NOT need to load the Scriptaculous libraries (e.g. effects.js, dragdrop.js) separately then you don’t need to upgrade.
July 3rd, 2008 at 4:47 pm
I had a problem running Ajax Edit Comments and found out it was the 1.2.6/jquery.min.js. Since WordPress 2.5.1 uses 1.2.3/jquery.js, I changed that line and then AEC worked again. I don’t know why it should matter but it does.
July 3rd, 2008 at 4:58 pm
@RT Cunningham: Thanks for the info. I’ve not had a problem with the versions yet, everything seems to function as before. Out of interest, do you know what error the Ajax Edit Comments plugin was throwing up?
July 3rd, 2008 at 5:05 pm
No errors. The comments wouldn’t load and the buttons/links in the edit panel wouldn’t work.
July 7th, 2008 at 2:43 pm
@david: Version 0.8 now adds checks for the indiviual scriptaculous libraries.
July 17th, 2008 at 11:22 pm
Hi Barry,
There’s a minor bug in the jquery-conflict code in v0.8 - replace the beginning of cs_handlejqueryconflict() with this:
$jquerypos = array_search(’jquery’, $args);
if(false !== $jquerypos && in_array(’prototype’, $args)) {
In the other code, the && operator binds too tightly, resulting in the jquerypos variable not actually be the position of the array.
August 5th, 2008 at 4:56 pm
Someone needs to post this over at http://www.ajaxtutorials.com.