Cloud Four Blog

Technical notes, War stories and anecdotes

Easy Steps To Speedup Your WordPress Blog

We recently finished optimizing several WordPress blogs for improved performance and I thought “wouldn’t it be great to share our experiences with everyone?” After all, when I look around at all the blogs I know and use, I see that very few are taking advantage of even the simplest performance improvement techniques — surely it’s just a matter of getting the information out there for everyone to use?

A quick search for “wordpress speedup” or “wordpress optimization“, however, reveals that we aren’t suffering from a dearth of information. On the contrary, many, many people have posted articles about their specific techniques and experiences (I’ve listed the best of these in the Related Articles section; you really should read them). This leads me to believe that most bloggers are either apathetic about their site performance or intimidated by the prospect of diving into something they know little about. I tend to think it’s probably the latter, so let’s see if we can make it a little less scary, eh?

Here at Cloud Four, we are big fans of the work done by the Yahoo! Exceptional Performance team to research and publish best practices for improving web performance. For us, the big finding was that most of the end-user response time — as much as 80% of the total page delivery time — occurs after the server has finished all its back-end work to create the page. Why such a long delay? Well, we’ve all been steadily increasing the number of Javascript, stylesheet, and image references on our fancy blog pages, and that means the browser has a lot of work to do before it can completely render the page for the reader. This finding is good news for most of us, since improving the page layout and rendering behavior are well within the skillset of almost anyone who can setup WordPress and install plugins.

What You Should Do Right Now

Here’s the short answer: install a couple plugins, add a few lines to your .htaccess file, and reap the rewards. It is almost certainly guaranteed that you will see an immediate improvement in your site performance, shaving seconds off each page load and impressing your readers. If you truly want to know how and why all this stuff works, you’ll enjoy reading the related articles for more information and insight.

1. Use Firefox, Firebug, and YSlow to measure yourself


The Yahoo! team has published their 34 rules for speeding up your web site and a tool for evaluating web sites against those rules. Strictly speaking, you do not need to install these tools, but I think you will enjoy seeing your YSlow score move from where it is today (probably an “F”) to where it should be (at least a “B”). And joy of joys, your actual site performance will improve accordingly.

2. Enable GZIP compression


Add the following lines to your .htaccess file (the AddOutputFilterByType should all be on one line). This action tells the web server to compress files before sending them to the browser, resulting in reduced bandwidth and faster delivery to the browser. Adding compression is a very safe option.


<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-javascript application/x-httpd-php application/rss+xml application/atom_xml
</IfModule>

3. Add an Expires Header


Add the following lines to your .htaccess file. This action tells the web server to add an Expires header for files that are unlikely to change in the near future. The reader’s browser will then cache the files until the expiration date, not even bothering to check for a new, updated version in the meantime. Note that if you DO change any files with a far future expiration date you will need to change the file’s name, otherwise any browser with a cached version will fail to fetch your new version. You are most likely to experience this issue with CSS or Javascript files, so don’t say I didn’t warn you.

    <IfModule mod_expires.c>
      ExpiresActive on
      ExpiresByType image/gif "access plus 1 month"
      ExpiresByType image/jpeg "access plus 1 month"
      ExpiresByType image/png "access plus 1 month"
      ExpiresByType text/css "access plus 1 month"
      ExpiresByType application/javascript "access plus 1 month"
      ExpiresByType application/x-javascript "access plus 1 month"
    </IfModule>
  

If mod_expires is not available on your system, you can try this instead:

    <FilesMatch ".(ico|jpg|jpeg|png|gif|js|css)$">
      Header set Expires "Sun, 22 Apr 2018 01:10:54 GMT"
      Header set Cache-Control "max-age=315360000"
      Header unset Pragma
    </FilesMatch>
  
4. Disable ETags


Add the following line to your .htaccess file. This action tells the web server to remove ETags from the HTTP response. For most websites, removing ETags will not affect your performance at all, but it will increase your YSlow score. Removing ETags is a very safe option.

    FileETag none
  
5. Install the PHP Speedy WordPress Plugin


The PHP Speedy WordPress Plugin is a real gem, implementing several of the Yahoo! best practices: combining multiple files to reduce HTTP requests, minifying Javascript and CSS, compressing the files via GZIP compression, and adding far future Expires headers. You should configure PHP Speedy to minify everything, compress Javascript and CSS, and add far future expire headers for both Javascript and CSS. There is no reason to enable GZIP compression for the web page itself, since we are doing that via apache.

Since this plugin modifies the way your page references Javascript and CSS files, take some care to test your site after activating your configuration. PHP Speedy appears to preserve the load order of the files, which is the main thing I care about. And if necessary you can exclude specific files from this optimization step. Still, I recommend that you test like crazy on this one.

6. Install the WP Super Cache Plugin


The WP Super Cache Plugin helps performance by dramatically reducing the time it takes the server to deliver the initial HTML file for the page. There are other steps you can take to optimize your server-side performance, such as eliminating unnecessary plugins and optimizing your page templates, but while you’re thinking about all that, this one little action will make a world of difference. My one configuration note here is to go ahead and enable “Super Cache Compression.” This option is disabled by default, but I recommend that you enable it and just run a quick test to ensure the page is being delivered correctly.

You can verify that the cache is configured and working correctly by visiting the site as an anonymous user and viewing the page source. Compressed pages being served by the cache should by quite fast and the last three lines of the page file will look something like the following.

      <!-- Dynamic Page Served (once) in 1.422 seconds -->
      <!-- Cached page served by WP-Super-Cache -->
      <!-- Compression = gzip -->
  

Results!

By using these techniques, and by adding a bit of image optimization and consolidation, we have seen dramatic performance improvements for the sites we’ve optimized. Typical page loading times have dropped from 5-10 seconds to one second (or less for pages cached by WP Super Cache).

Without sacrificing any page functionality or quality, we have been able to:

  • reduce the empty cache total size by 50% or more
  • reduce the empty cache HTTP requests by 50% or more
  • reduce the primed cache total size by 90% (!)
  • reduce the primed cache HTTP requests to as few as 1 or 2 requests (!)

Where Next?

Well this first part was certainly easy: edit one file (.htaccess) and install two WordPress plugins. These simple steps have probably provided some immediate relief for your readers, and that’s a good thing. From here, I would strongly suggest you review the related articles for other front-end improvements, such as optimizing images and using sprites to reduce the number CSS images on your site. There’s quite a bit more you can do without becoming a programmer or system administrator.

If you do have administrative access to your server, however, you can also begin experimenting with ideas to improve the back-end server performance. You might consider installing a PHP accelerator, such as eAccelerator, to speedup PHP script execution. Or you might want to expend some effort tuning MySQL for your site. For most people, however, these advanced topics are beyond their skill and training, or are simply unavailable in their current hosting environment.

If you decide try any of the techniques in this article, I’d like to hear about your experience, and about what you think you’ll try next.

Good luck!

WordPress Plugins You Need

Resources

Speaking at Velocity Conference

I’m speaking today at the Velocity Conference in San Francisco. Back in 2003 when John and I spent weeks working on performance, we never thought performance would reach the point where a whole conference would be focused on it. It’s an amazing thing.

We’re going to be presenting our Mobile Concurrency Test and the initial results we’ve received.

Make Your Blog Faster & Help Save the Environment

For those in the Portland area, I’m going to be leading an informal session at this week’s Beer and Blog on how to optimize your blog for performance and why doing so is good for the environment.

More on how performance is connected to the environment in a moment, but first, the details on when and where:

Beer and Blog – Make Your Blog Load Fast & Save the Environment
Green Dragon Bistro & Brewpub
928 SE 9th Ave.
Portland, Oregon 97214
RSVP | Add to Calendar | Map

The Impact of Data Centers on the Environment

HP Efficient Computing at SNWEveryone is aware that our ability to reduce our energy consumption is a key component to reducing the impact we have on the environment.

However, it wasn’t until I was asked to speak to the Storage Networking Industry Association (SNIA) at Storage Networking World last fall that I realized how important this is for those who run data centers.

At the time, I observed:

Several businesses are now being told that they cannot bring any more power into their data centers. The power company is simply refusing to provide them with more capacity.

In many cases, the cost of powering and cooling a data center exceed the costs of the hardware within two years.

The people in the storage industry get it. The SNIA has started the Green Storage Initiative to foster innovative ways of reducing power consumption in data centers.

The question is are those of us who are web developers doing our part? Sadly, no.

Web Site Gluttons

Web developers live insulated lives. We have broadband at our homes and our offices and it shows. We’ve stopped paying attention to the size of web pages.

Andrew King recently highlighted research showing that the average size of web pages has doubled since 2003. “Longer term statistics show that since 1995 the size of the average web page has increased by 22 times, and the number of objects per page has grown by 21.7 times.”

Growth of Average Web Page Size and Number of Objects

Source: http://www.websiteoptimization.com/speed/tweak/average-web-page/

In addition to the size of web pages, few sites are optimized to ensure that browsers cache the files and don’t request the same files repeatedly.

Steve Souders recently conducted a thought experiment on how much CO2 would be saved by optimizing the Wikipedia home page. He used the CO2stats.com estimate that “three minutes on a Web site generates three grams of CO2 – roughly equal to the amount one person generates by breathing for 4.5 minutes.”

Steve estimated that the optimization could save “5,000 kilowatt-hours per year or approximately 500-1000 pounds of CO2 emissions.”

Why Now?

I’ve been interested in web optimization for ever since it saved my prior company tens of thousands of dollars a few years ago. I’ve been speaking on the topic whenever possible and trying to help web developers understand how much benefit they can get by optimizing their pages and how easy it is to do.

A couple of weeks ago, I finally watched An Inconvenient Truth. At the conclusion of the film I started thinking about what more I could do. I’m getting a bike ready to use for my commute to work. I’m reducing the energy I use. I’m contemplating a vegetarian diet.

And I’ve redoubled my commitment to getting web developers to take site performance seriously. It saves money, improves the experience for your customers, and it’s easy to do.

Most importantly, if you care about global warming, optimizing your site is a moral imperative.

So come join us tomorrow at the Green Dragon to make your blog faster and reduce the energy it consumes.