HOME     SITEMAP     RSS     TWITTER     EMAIL    
Search:   

FollowSteph Follow Steph as he posts Blog Blazer Friday
 
 

3 Quick and Simple Tricks to Speed Up WordPress

Improve Performance

There are many ways to improve the performance of your WordPress blog, and today we’ll be focusing on three simple and easy techniques. That is, instead of dealing with caching and other advanced topics, we’ll instead focus on how to improve the performance of your WordPress blog by just making some small and minor changes to your WordPress theme.

The performance of your blog basically comes down to 3 main issues in order of importance:

  1. The number of calls to your database
  2. The amount of code that needs to be executed.
  3. The amount of data that needs to be downloaded (images, etc.)

Beyond this you’re getting into the more advanced topics such as caching, etc. And you shouldn’t really be looking at the advanced techniques until you resolve these basic issues first.

1. The number of calls to your database

Every single call to your database is very expensive (this is true for all web application, not just a WordPress blog). It’s not just marginally more expensive, it’s critically more expensive. The good news here is that there is a lot, and I do mean a lot, of room for improvement. Most themes out there completely ignore this issue and just call the database whenever they want any type of data (which is understandable for generic themes, but not for custom themes). In any case, this is very bad. And I do mean very bad. Well ok, maybe it’s not so bad if you have barely any traffic, but as soon as your blog starts to take off it will quickly hamper your performance.

For example, looking at the latest default WordPress theme for version 2.7 (the “classic” theme isn’t much better), in the “header.php” file, you can find:

<meta http-equiv=”Content-Type” content=”<?php bloginfo(‘html_type’); ?>; charset=<?php bloginfo(‘charset’); ?>” />
<title><?php wp_title(‘&laquo;’, true, ‘right’); ?> <?php bloginfo(‘name’); ?></title>
<link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); ?>” type=”text/css” media=”screen” />
<link rel=”alternate” type=”application/rss+xml” title=”<?php bloginfo(‘name’); ?> RSS Feed” href=”<?php bloginfo(‘rss2_url’); ?>” />
<link rel=”alternate” type=”application/atom+xml” title=”<?php bloginfo(‘name’); ?> Atom Feed” href=”<?php bloginfo(‘atom_url’); ?>” />
<link rel=”pingback” href=”<?php bloginfo(‘pingback_url’); ?>” />

There’s more, but this is enough for our example. If we look at the code above, the method bloginfo() calls the database for every new value. In our example I count 7 new and different values out of 9 bloginfo() calls, hence 7 database calls. WordPress is smart in that once a call for a specific value is made (say “name”) it will cache and re-use the value for that one web request. That’s good and it does help (kudos to the WordPress developers for this), and in our case it saves two database calls. But on the next page request, we still have another 7 database calls to make.

The good news is that we can drastically improve the performance of our blog theme above with some simple changes:

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8” />
<title><?php wp_title(‘&laquo;’, true, ‘right’); ?>My Blog’s Name</title>
<link rel=”stylesheet” href=”https://www.myBlog.com/styles.css” type=”text/css” media=”screen” />
<link rel=”alternate” type=”application/rss+xml” title=”My Blog’s Name RSS Feed” href=”https://www.myBlog.com/rssFeed” />
<link rel=”alternate” type=”application/atom+xml” title=”My Blog’s Name  Atom Feed” href=”https://www.myBlog.com/atomFeed” />
<link rel=”pingback” href=”https://www.myBlog.com/pingBackUrl” />

These simple changes has dropped the number of database calls from 7 to 1!!! That’s very significant, especially since these expensive. And that’s every time a user calls every page!

Sure there is a small penalty, but it’s extremely minor. For example if we change our blog’s name then we need to manually change the theme as well. But how often do you change your blogs name? I’ve never changed the name of this blog since I’ve started it and nor do I ever plan to. And why would I? I would lose all my marketing and branding efforts.

If you go through the rest of your theme, I’m sure you can extract a lot of database calls. Especially on the header, the footer. But if you look, I’m sure you can find similar code all over the place. Of course don’t go crazy, but do pay close attention to the database calls. Remember this is a simple theme. In a more complex theme you might easily be able to save yourself a good 10-20 database calls, if not more.

2. The Amount of Code to Execute

Very similar to the above tip, look around your theme for places where there are function calls that you don’t need. Trim down your blog’s theme.

A common place to find code that’s executed a lot that doesn’t necesarily need to be is plugins. Some plugins are great and really help improve your blog (such as Akismet for comment spam). But not every plugin is created equal. Some plugins are just badly written and really slow down the performance of your blog. Therefore look at all the plugins you have installed on your blog and limit yourself to only those that create real value. Ask yourself: s this plugin really worth it? And the more traffic you have, the more you need to ask yourself this.

Without getting too technical, since this is suppose to be quick and simple tricks, look for loops in the code of your blog’s theme (“for” and “while” loops). Examine the code that’s executed in these loops because it’s probably executed many times (which is why it’s in the loop in the first place). Is it necessary? Does it really provide something of value?

3. The amount of data that needs to be downloaded

The next most important you should be doing is looking at the main images on your blog. Is your logo’s filesize as small as it can be (while still looking good)? Can you shrink it? Then look at all the images that appear on virtually every page (the RSS subscription icon, the email icon, etc.). Can they be shrunk as well? And don’t just think about shrinking them, ask yourself if you need them in the first place? Do all the images serve a real purpose? Sure that bright yellow flashing gif animation of a flying toaster on the footer is kinda cool retro 1995 style, but is it really needed? That’s one less image you have to download and process.

Another easy place to reduce image size is on the images within your individual blog posts. Are they as small as they can be? Are you using 100kb image files or are you shrinking them down to 10-40kb? Sometimes a little loss of quality can more than halve your image file size, without a noticeable difference in quality to the un-attuned eye.

You can also look at shrinking the size of your css (Cascading Style Shee) file. Are all the styles need and used? If you’re a web geek, you can even consider removing all the whitespace to shrink the filesize. Just don’t do it manually, use a tool to help you out. The same goes for your Javascript files.



 
Like this article?

Comments:

  •     An Ill Corporate Wind Is Blowing - And Many Are Not Helping One Byte | The Recursive ISV
    · January 8th, 2009  · 4:59 am  · Permalink

    […] Steph’s got a nice little article on optimizing WordPress basics that is well worth a read. […]

  •     Mark Gladding
    · January 9th, 2009  · 7:21 am  · Permalink

    One other way of reducing hits on your database is to use the SuperCache WordPress plugin. This will cache the output of your site and store the pages as html files. This not only avoids database overheads but also the overhead of PHP. It’s smart enough to regenerate the cache whenever your content changes. It doesn’t serve cached pages to registered users or users who have commented on your blog. This not really a problem as 99% of visitors don’t fall into either of these categories. It works well when you get a surge of Digg readers. One extra benefit of SuperCache is that it gzips your pages to reduce the amount of data being transferred.
    The other thing I’ve done is to use a Content Delivery Network (CDN) to serve all the images on my site. This has a number of advantages. A good CDN will have multiple servers strategically placed around the world. When a visitor lands on your site, the closest physical server to that individual visitor is chosen to serve your content. This reduces latencies introduced by physical distance.
    It also means that your content is being served by at least two domains. Browsers limit the number of simultaneous requests they will make to a single domain. Having two domains doubles this number. I think the limit for IE6 & 7 is around 2. IE8, Firefox 3 and Google Chrome will make around 8 simultaneous requests to a single domain.
    I’m using http://www.cachefly.net for my site http://www.ebooksjustpublished.com. It’s the only realistically priced CDN service I’ve found. Their entry level plan, which will be more than adequate for most blogs and web sites is $15 per month.
    One thing you should do before performance tuning your site is to do some measurements. The best tool I’ve found for this is the free Firefox plugin from Yahoo called YSlow (https://developer.yahoo.com/yslow/). This not only measures your site performance and gives it a grade, it also gives you a list of suggestions on how to improve it’s performance. I can’t recommend this tool highly enough. It’s the best thing to come out of Yahoo since Seth Godin!
    Having said all that my site went down the other day under a load spike. Talking to my hosting provider it seems the server received too many simultaneous requests, causing Apache to run out of memory, hit the VPS memory limit and end up being killed by some daemon. I guess that’s the risk you take when running on a $10 plan with a 160MB VPS. Time to upgrade to their next level plan I think. What I’d really like is a plan that scales automatically to accommodate load spikes but only charges you for the resources you use.

  •     Steph
    · January 12th, 2009  · 1:02 pm  · Permalink

    Hi Mark,

    Thanks for filling in the advanced tips, at least what I consider advanced tips!

    Thank you 🙂

  •     The IT Juggler
    · February 17th, 2009  · 7:23 am  · Permalink

    Hi,

    This is a great article. I’ve been spending a bit of time trying to get the best performance out of my self-hosted WordPress and found a great plugin that dropped load and render time. I’ve posted a blog about it here on https://itjuggler.ollis.id.au/2009/02/16/wordpress-on-speedy-wp/

    Steve

  •     » An Ill Corporate Wind Is Blowing – And Many Are Not Helping One Byte
    · October 26th, 2010  · 1:40 am  · Permalink

    […] […]

  •     An Ill Corporate Wind Is Blowing - And Many Are Not Helping One Byte
    · November 23rd, 2010  · 12:17 pm  · Permalink

    […] […]

Write a reply:





 


SOFTWARE AND BOOKS BY STEPHANE GRENIER:

LandlordMax Property Management Software

LandlordMax is the EASIEST
Property Management
Software available!
Try it for free!

Real Estate Pigeon

Real Estate Pigeon
The place to ask and answer
all your real estate questions

Blog Blazers: 40 Top Bloggers Share Their Secrets to Creating a High-Profile, High-Traffic, and High-Profit Blog!

Blog Blazers is a book that
features secrets from the
Top 40 Bloggers on the web

How to Generate Traffic to Your Website ebook

How to Generate Traffic to
Your Website
is an ebook for
to you achieve success


 

FollowSteph
More resources from Stephane Grenier:
PUBLICATIONS
For people who work on the web
Blog Blazers
How to Generate Traffic to Your Website
 
SOFTWARE
The EASIEST Property Management Software available!
LandlordMax


Copyright @2003-2024
LandlordMax Property Management Software

Disclaimer: This is a personal blog about my thoughts, experiences and ideas. The contents of this blog are for informational purposes only. No content should be construed as financial, business, personal, or any other type of advice. Commenters, advertisers and linked sites are entirely responsible for their own content and do not represent the views of myself. All decisions involve risks and results are not guaranteed. Always do your own research, due diligence, and consult your own professional advisors before making any decision. This blog (including myself) assumes no liability with regard to results based on use of information from this blog. If this blog contains any errors, misrepresentations, or omissions, please contact me or leave a comment to have the content corrected.