Use Google Libraries: A Plugin to Improve Script Loading Performance in WordPress
A number of the javascript libraries distributed with Wordpress are also
hosted on Google’s AJAX Libraries API.
This plugin allows your Wordpress site to use the content distribution
network side of Google’s AJAX Library API, rather than serving these files from your WordPress install directly.
This provides numerous potential performance benefits:
- increases the chance that a user already has these files cached
- takes load off your server
- uses compressed versions of the libraries (where available)
- Google’s servers are set up to negotiate HTTP compression with the requesting browser
For a more detailed look see Dave Ward’s 3 reasons why you should let
Google host jQuery for
you.
Supported Libraries and Components
Download
Latest version: Download Use Google Libraries: A Plugin to Improve Script Loading Performance in WordPress v1.0.9.2 [zip]
Support Development
If you find this plugin useful feel free to leave a tip.
Installation
Upload the use-google-libraries folder to the /wp-content/plugins/ folder.
Activate Use Google Libraries through the ‘Plugins’ menu in WordPress.
Er… That’s it really.
FAQ
Q. What happens when Google updates their library versions?
A. Google has stated that they intend to keep every file they’ve hosted
available indefinitely, so you shouldn’t need to worry about them
disappearing.
Q. Why isn’t in doing anything?
A. Firstly, if you are using a caching plugin, flush the cache or
temporarily disable it to be sure it’s not doing anything. That said,
I’ve done my best to make Use Google Libraries gracefully step out
of the way when things are not as expected. While not, perhaps,
giving you the greatest benefit it helps ensure you site doesn’t just
flat out stop working.
In general, anything that calls wp_eneque_script before ‘init’ will
stop Use Google Libraries from loading. Please see the section on
Incompatible Plugins and Incompatible Themes for specific
information.
Changelog
1.0.9.2
- Hopefully fix issue with plugin loading for some users
1.0.9.1
- Added Incompatible Plugins and Incompatible Themes sections
to the README
1.0.9
- more https detection
- inline jQuery.noConflict()
1.0.7.1
- fix previous fix (whoops!)
1.0.7
- Quick and dirty workaround for scriptaculous loading (thanks to
Gregory Lam for bringing it to my
attention
1.0.6.1
- moved location of the Changelog section in the README
1.0.6
- Disables script concatenation in WordPress 2.8, since it seems to have
issues when some of the dependencies are outside of the concatenation. - Persists flag to load scripts in the footer in WordPress 2.8
1.0.5
- It should detect when a page is loaded over https and load the libraries over https accordingly
- It no longer drops the micro version number from the url. The reasons for this are twofold:
- It ensures the version requested is the version received.
- Google’s servers set the expires header for 12 months for these
urls, as opposed to 1 hour. This allows clients to cache the file
for up to a year without needing to retrieve it again from Google’s
servers. If the version requested by your WordPress install
changes, so will the URL so there’s no worry that you’ll keep
loading an old version.
Popularity: 100%
134 Comments
Leave a Reply
![[RSS: Posts]](http://jasonpenney.net/wp-includes/images/rss.png)




Odd and the Frost Giants
The Lies of Locke Lamora
More Information Than You Require
A Christmas Carol
7th Son: Descent


[...] 插件主頁:http://jasonpenney.net/wordpress-plugins/use-google-libraries/ [...]
[...] Google Libraries 访问插件主页 [...]
[...] 7.Use Google Libraries,如果你的博客使用了JavaScript、AJAX,即直接从Google AJAX Libraries中加载,提高速度,较少主机负载,您的主机能跟Google的服务器比么? [...]
Hey Jason, I’m sure it took you a while to figure this all out. I have created several plugins in the past, and never had a problem with load time. Under what circumstances can load time before so compromised that is worth spending time figuring out exactly how to make the changes you have suggested here.
Hi,
this is a great plugin! Thanks!
But unfortunately i am to stupid to include things the right way and can’t get anything to work. I wanted to implement a tabs in my sidebar and don’t have any idea how to include the scripts now. Could you help me out here? I tried the local js-Files but i’m doing something wrong here…
Hi,
Great plugin! Have you been thinking about adding the rest of the libraries (especially SWFObject), which are these days available from Google Libraries?
Thanks. I’ve been planning to add the remaining libraries that are available, as well as a handful of other improvements as soon as I can find the time. Glad you’re finding it useful!
I think that SWFObject is already included, though it is not included in lists on this page or on description on wp.org.
Do you plan to include suggestion I wrote here (which didn’t pass spam test) which I got from wp-hackers about inline no.conflict code? Tynan Colin Beatty sent code a month ago and I still didn’t reply to him since you didn’t reply to me :(
I’ll have to double check. I think i ‘future proofed’ SWFObject (so if WordPress Core started including it UGL would grab the one from Google). I apologize about not responding. I thought I had. If you have some code I can use for the noconflict issue please let me know.
It seems the spam-filter issue is fixed at least.
I wrote a comment here about a month ago with this, maybe it is in your spam queue or something like that.
Point is that I asked on wp-hackers and got one response with some code example. See it here.
Have you done anything about this?
I did give it a go, but I had some issues making it work and haven’t had time to try again.
I agree that inline noconflict would be really nice.
Is this plugin supposed to work with wp_enqueue_script? It doesn’t appear to be for me and the Other notes in the WordPress plugin directory doesn’t mention the function. Yet it’s my understanding that wp_enqueue_script is the preferred way to load scripts in WordPress. Am I missing something?
That’s all this plugin does. If you call
wp_enqueue_script('jquery');in you theme or plugin then it should pull it from the Google Libraries CDN instead of from your local version once the plugin is activated.What exactly are you trying to do that isn’t working?
On WordPress 2.8.4 with Use Google Libraries 1.0.7.1, I’ve been trying to get jquery-ui-core to load on my author pages. I’ve tried a couple variations on using wp_enqueue_script but the page source shows I keep getting the copy of jquery-ui-core installed with WordPress. The last thing I tried was putting this bit of code in my header file, above wp_head():
<?php if ( is_author() ) wp_enqueue_script( 'jquery-ui-core' ); ?>fixed your code — Jay
I’m guessing it’s one of two things.
You may need to do that at the init hook. So in your theme’s functions.php you could add:
function my_init() {
if ( is_author() ) wp_enqueue_script( 'jquery-ui-core' );
}
add_action('init','my_init');
It’s also possible another plugin is getting in there and insisting on the local version, or something changed in WordPress core in 2.8.3+ that I need to take into account. Are you running any other plugins?
Tried that and it didn’t appear to work for me, but I did find a work around that does. I do use a considerable number of plugins, so it’s possible something in one of them is causing the problem. Are there any specific plugins you know of that interact badly with Use Google Libraries?
[...] Use Google Libraries - Uses common javascript libraries from Google’s AJAX Libraries CDN. Saves your server and your readers some loading and time. You know, unless Google goes down [...]
on my site, enabling this doesn’t seem to do anything as far as i can tell. firebug is still telling me that all of the scripts are being loaded from the site’s domain as opposed to remotely from the google url.
anyone have a trick to getting this to work?
Maybe this is happening because there is some plugin that is in conflict with this one. For example, I found that when plugin Delink Comment Author is activated, scripts are loaded from blog’s server, not from Google’s.
BTW, you can check from where your scripts are loaded by viewing source code of page (press CTRL + U or go to View → Page Source). If there is domain googleapis.com, it means that Google’s server is used.
I have been using FireBug to trouble shoot this (and a few other issues) and the javascript files are most definitely not being loaded from the google api’s site.
With that said, I do have a billion other wordpress plugins installed, but not the one that you mention (delink). Will keep looking into it, but don’t really know where to start as far as troubleshooting where things are going wrong.
I just installed this in WordPress 2.8.6 using the Thematic theme, and activated it, but it doesn’t appear to be doing anything, Wordpress is still using its own local jquery libraries.
I was running into the same issue as everyone else looking for help. I successfully installed the plugin, and I was even able to see jQuery in the header, but no response from my scripts. I was even able to manually load
into my header and successfully achieve the desired result.When all was said and done my fix is as follows. I had manually loaded fancybox, easyslider, and coda button into my header. Yes I know there’s plugins available for each of those scripts, but the plugins load up to much junk, and I’m building something a little more streamlined and responsive. I put each of the scripts into “noconflict”, even fancybox, dropped them below wp_head, removed the jQuery script which I had manually put in. And wallah, it worked as it should. No additional jQuery scripts, and no wp_enqueue_script. After that I compressed my scripts, http://javascriptcompressor.com/ and with jQuery now loading as it should from Google, my load times have improved significantly.
I’m sure part of my issue was related to conflicting scripts, but the main issue seemed to be that my scripts were loading before jQuery. If your problem sounds similar, have a look at whats loading first. Always the simple fix. Good luck folks.
Somehow, the LightBox 2 plugin conflicts with this one. I just verified this with a mass plugin-deactivation and subsequent one-by-one activation.
PROBLEM: I just updated your plugin to 1.0.9.1 and my blog is having major problems at -
http://rubylearning.com/blog/
Some errors:
Warning: call_user_func_array() [function.call-user-func-array]: Unable to call JCP_UseGoogleLibraries::setup_filter() in /home/.renaissance/talim/rubylearning.com/blog/wp-includes/plugin.php on line 339
Warning: call_user_func_array() [function.call-user-func-array]: Unable to call JCP_UseGoogleLibraries::replace_default_scripts_action() in /home/.renaissance/talim/rubylearning.com/blog/wp-includes/plugin.php on line 414
Warning: call_user_func_array() [function.call-user-func-array]: Unable to call JCP_UseGoogleLibraries::remove_ver_query_filter() in /home/.renaissance/talim/rubylearning.com/blog/wp-includes/plugin.php on line 166
I am using the latest Thesis theme 1.6 and the latest WordPress version.
Please help or at least point me to the next immediate older version of the plugin.
Thanks.
Are you running php4? All my systems have php5, so if I were to guess at what’s causing the issue that’s where I’d start.
If that’s the case I’d recommend grabbing 1.0.7.1 from http://wordpress.org/extend/plugins/use-google-libraries/download/
Jason, thanks for your quick reply. As of now, I have disabled the plugin. I have PHP Version : 5.2.0-8+etch15
Any other clue?
Huh. I’ve tested with PHP 5.2.10 and PHP 5.3.0. Other than that I’m at a bit of a loss at the moment.
No problems. Will wait for you to fix the issue. Thanks.
i’d just like to confirm that i am to having the problem with call_user_func_array() [function.call-user-func-array]: Unable to call JCP_UseGoogleLibraries::setup_filter(), also on php5. i wish i could get you more details why this is happening, but i am myself at a loss.
If either (or both) of you could let me know if 1.0.9.2 fixes the issue I’d appreciate it.
Jason, 1.0.9.2 fixed the issue. Thanks.
yup. that did it. many thanks for your quick turnaround. well done.