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

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

  1. [...] 插件主頁:http://jasonpenney.net/wordpress-plugins/use-google-libraries/ [...]

  2. [...] Google Libraries 访问插件主页 [...]

  3. [...] 7.Use Google Libraries,如果你的博客使用了JavaScript、AJAX,即直接从Google AJAX Libraries中加载,提高速度,较少主机负载,您的主机能跟Google的服务器比么? [...]

  4. JC Penney EDI says:

    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.

  5. Jenny says:

    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…

  6. Miikka says:

    Hi,

    Great plugin! Have you been thinking about adding the rest of the libraries (especially SWFObject), which are these days available from Google Libraries?

    • Jason Penney says:

      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!

      • Milan says:

        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 :(

        • Jason Penney says:

          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.

  7. Mark says:

    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?

    • Jason Penney says:

      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?

      • Mark says:

        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

        • Jason Penney says:

          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?

          • Mark says:

            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?

  8. [...] 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 [...]

  9. mike w says:

    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?

    • Milan says:

      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.

      • gekido says:

        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.

  10. Kenneth Rapp says:

    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.

  11. Rob says:

    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.

  12. Blaenk says:

    Somehow, the LightBox 2 plugin conflicts with this one. I just verified this with a mass plugin-deactivation and subsequent one-by-one activation.

  13. Satish Talim says:

    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.

Leave a Reply

U Comment/I Follow

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>