Speed Up WordPress By Using the WordPress.com CDN for Javascript Files

speed
photo credit: Tc Morgancc
Here’s a quick performance tip for self-hosted WordPress sites. WordPress loads a number of scripts from its /wp-includes/ directory, depending on what you have active on your site. Use WordPress.com Libraries is a new plugin, created by Automattician and plugin developer Ben Lobaugh. Once installed, it automatically switches the URL on built-in WordPress Javascript files to serve them from the WordPress.com CDN instead. Rather than taxing your local server, you offload those requests to WordPress.com, thereby decreasing load time and bandwidth consumption.

Here’s a quick sample of a site’s scripts before installing the plugin:

[html]<script type=’text/javascript’ src=’http://example.com/wp-includes/js/jquery/jquery.js?ver=1.10.2′></script>
<script type=’text/javascript’ src=’http://example.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1′></script>
<script type=’text/javascript’ src=’http://example.com/wp-includes/js/jquery/ui/jquery.ui.core.min.js?ver=1.10.3′></script>
<script type=’text/javascript’ src=’http://example.com/wp-includes/js/jquery/ui/jquery.ui.widget.min.js?ver=1.10.3′></script>
<script type=’text/javascript’ src=’http://example.comm/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js?ver=1.10.3′></script>[/html]

The plugin automatically changes the script URLs in use to call the ones hosted on WordPress.com:

[html]<script type=’text/javascript’ src=’http://wordpress.com/wp-includes/js/jquery/jquery.js?ver=1.10.2′></script>
<script type=’text/javascript’ src=’http://wordpress.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1′></script>
<script type=’text/javascript’ src=’http://wordpress.com/wp-includes/js/jquery/ui/jquery.ui.core.min.js?ver=1.10.3′></script>
<script type=’text/javascript’ src=’http://wordpress.com/wp-includes/js/jquery/ui/jquery.ui.widget.min.js?ver=1.10.3′></script>
<script type=’text/javascript’ src=’http://wordpress.com/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js?ver=1.10.3′></script>[/html]

Don’t look for a settings panel, as it doesn’t come with any options. You simply install the plugin, activate it and you’re good to go. Everything happens automatically in the background. As a general warning, make sure to check through your site after installing this in case anything has broken. In my tests everything worked fine but if you’re running an older version of WordPress, it may not work predictably. The plugin is still in development and will likely receive updates to improve it over time.

It’s tough to say how much of a performance boost you’ll get and how much bandwidth you’ll save by installing this plugin, because it depends on which scripts you have active on your website and how heavy your traffic is. However, every small bit helps, especially if you’re not already using a CDN. Install the Use WordPress.com Libraries plugin for free from the WordPress plugin directory.

17

17 responses to “Speed Up WordPress By Using the WordPress.com CDN for Javascript Files”

  1. Yeah, I would be worried about version conflicts. I’m sure that is a solvable problem, but realistically, I’m not sure that using the WordPress.com systems for this is any better of an idea than using the Use Google Libraries plugin.

    The main problem with offloading library loads like this is simply one of connectivity. You’re relying on your site’s viewers being able to connect to that external service (Google, wp.com, etc) to load the JS files. While this is relatively true in most places, in many cases it is not, which is why the default is to package files with the core, so that you have everything needed for the site to work anywhere.

    With Google, they maintain version numbers as part of the request, so you can be assured that the version conflict problem won’t happen. WP.com does not currently do this that I know of, although that would be easily solvable on their end.

    It’s likely that WP.com has more of the libraries than Google’s JS library mirrors do though, so there is that.

    In the end, I’d suggest using the Google libraries plugin if you want this sort of speedup, and even then it’s a minor speedup at best. Most people don’t use tons of Javascript on the front-end of their sites. For those that do, reducing that would be better in the long run. Sure, loading jQuery from a CDN is faster, but it can be problematic for some users.

    • Exactly, thanks for the thorough explanation Otto.

      I’m located in one of those countries where wordpress.com is blocked entirely, so if I were to install this plugin, for starters my site would stop functioning for myself and with it all visitors from here and other countries where wordpress.com is blocked…

  2. There are some stability concerns. Once JS libraries are updated in trunk and on WP.com (which follows trunk), the current version of the plugin may no longer work with stable WordPress versions:

  3. Hey all – Thanks for the interest! I did not think this plugin was going to kick off so fast! After chatting with Nacin yesterday I realized there could be some issues with how WordPress.com merges files from WordPress trunk. I am currently running this plugin on my personal site with no issues but if you want to run it on yours make sure you check for breakage after installing it, and monitor when 3.9 development begins.

    I am looking into how to make a proper solution to this as well.

  4. Until the plugin has a better way of supporting the scripts it has been removed from WordPress.org so that users do not install it and suddenly have a site behaving erratically.

    For anyone still interested in checking it out it can still be found in my Github account. Just keep in mind that updates to core libraries will appear on WordPress.com before they appear in the official WordPress releases. If your site is using up to date code then it may not be an issue if one of the WordPress.com linked libraries is updated before your WordPress site is due to backward compatibility.

    I am working with the WordPress.com team to create a good solution, but until it is done I have decided the plugin should be pulled from the plugin repository so that it does not inadvertently harm anyone’s site. It is still fair game on Github and pull requests are welcome :)

    https://github.com/blobaugh/use-wpcom-libraries

Newsletter

Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.