Line25

WordPress Fat-Loss Diet to Speed Up & Ease Load

Read the full post

Last week we looked at some useful plugins to enhance and protect WordPress, following on with the WordPress topic let’s look at how you can tweak your WordPress install to increase the speed of your site and ease the load on your web servers. We’ll be putting the front end code on a strict diet, while trimming the fat from the database to produce a fast, lean website that doesn’t clog up your server’s resources.

Despite its general awesomeness and wide adoption across the web as both a blogging platform and a trusty CMS, it’s no secret that WordPress is a greedy old memory hog. This high memory usage soon becomes apparent when your blog receives a decent number of visitors and your blog goes missing due to your server throwing in the towel.

Installing one of the many caching plugins fixes 90% of these server problems, while upgrading your server specs solves the rest. But it’s not all about uptime and downtime, we also want a speedy site that loads in a flash every day. Follow this 10 step exercise regime for your blog and you’ll take it from a slobbering podgy couch potato to a ripped and finely tuned pentathlon athlete.

Step One – Install a Caching plugin

Caching solves 90% of those server problems. It dramatically eases the load on your server by presenting static files to users instead of making numerous calls back and forth to the database. There’s a hand full of plugins to choose from including WP-Cache, WP Super Cache, Hyper Cache and W3 Total Cache. Check out this handy post from Tutorial9 for a more thorough overview.

My choice goes with W3 Total Cache as it combines not only page caching, but also database caching, browser caching, object caching and minify settings.

Step two – Lose the plugins & widgets

WordPress plugins are what makes the application so powerful, but there’s some that you could either remove altogether, or hard code into your theme. Each plugin creates extra processes your server will have to resolve each time a page is loaded so removing these processes can really help speed up your site.

Instead of using a plugin to insert your Analytics code into your page footer, do it yourself. Rather than rely on a plugin to insert share buttons, add them to the theme yourself. Chances are some of these plugins will be bloated with unnecessary code and will call their own CSS and Javascript files for features you might not even be using.

Step three – Hard code your templates

This one is definitely more for the designers and developers who run their own sites, as opposed to sites that need to be editable for clients, or for public themes. Swapping out the WordPress PHP tags for plain old HTML can really help increase the speed of your site as you’re essentially cutting out the extra steps WordPress has to take. Let’s take <?php wp_list_pages(); ?> for example. Each time the your webpage is loaded, WordPress has to check the database for the number of pages it has stored, then inject them into your theme as a series of <li> elements.

Instead, link up the pages directly in your theme file:

<ul>
	<li><a href="/category/articles">Articles</a></li>
	<li><a href="/category/inspiration">Inspiration</a></li>
	<li><a href="/category/tutorials">Tutorials</a></li>
	<li><a href="/about">About</a></li>
	<li><a href="/advertise">Advertise</a></li>
	<li><a href="/contact">Contact</a></li>
</ul>

The same can be done for lots of standard PHP tags in your WordPress theme, what about <?php bloginfo('name'); ?>, <?php wp_list_categories(); ?> or <?php bloginfo('stylesheet_url'); ?> Once your site is set up, chances are these elements aren’t going to change anytime soon.

Step four – Minify your HTML & CSS

Minifying can help squeeze out every last Kilobyte from your front end files, speeding up your pages by whole milliseconds. If you picked out W3 Total Cache as your caching plugin of choice, you have Minify settings right at your fingertips. Minifying strips out white space and comments from your HTML and CSS files, which lowers the filesizes and subsequently allows for faster load times.

Step five – Smush your images

Images make up a large portion of the files that are downloaded during every page load. Some files, like header images and other theme related graphics are loaded on every page so it’s worth making sure these images are as lean as they can be. Upload and replace your theme image files with versions that have been run through the Smush.it engine. For all the other images uploaded through WordPress, the WP Smush.it WordPress plugin helps optimize images as they’re used.

Step six – Disable post revisions

Post revisions are a handy feature if you’re running a multi-author blog, but for most of us it’s an unused feature of WordPress. Post revisions can seriously bloat your database with multiple copies of posts, adding extra MBs to your SQL files. To turn it off, simply add the following code to your wp-config file:

define('WP_POST_REVISIONS', false );

Don’t forget to delete existing post revisions using the following SQL query, through phpmyadmin or similar (as always, create a backup before making such changes):

DELETE FROM wp_posts WHERE post_type = "revision";

Step seven – Delete all spam comments

Just like a hoard of post revisions, spam comments that have been captured by Akismet can take up some serious database space, especially if you haven’t done a spring clean in a while and there’s thousands of comments polluting your spam section. Thankfully it’s easy to nuke them all with the swift click of a button in the WordPress admin area.

Step eight – Run a Clean Options check

If your blog is a few years old, chances are you will have installed plugins that you don’t use anymore. Most plugins are developed well and clean up after themselves when they’re uninstalled, unfortunately there are others than leave behind all their settings and information. These unused tables can bloat your database so it’s useful to purge them to free up space. The WordPress plugin Clean Options is a handy tool for giving your database a clear out. It looks for tables that are no longer in use then gives you the option of deleting them.

Step nine – Optimize your database

Over time your database develops clutter. Just like the drefragging of a hard drive, optimizing your database removes this clutter and puts everything back in its place. There’s two easy methods of doing so, with a plugin or via phpmyadmin. If you have WP-DBManager installed, this plugin has the optimize feature built in and can even schedule the job to run automatically.

Step ten – Purchase multiple servers

You may reach a point where even your trimmed WordPress install still breaks even the most finely tuned and highly specced VPS or dedicated server under high load. The next step is to not only increase your server size, but also in numbers. Using one highly specced server purely for MySQL allows the database to use as much resources as it needs, while the PHP and front end files reside on a smaller server.
Use the define('DB_HOST'); setting in the wp-config.php file to specify the IP of the server the database is living on.

Free web shadows pack for every subscriber

Join the mailing list to have new content delivered straight to your email inbox. Every subscriber gets a free pack of realistic web shadows.

Written by Chris Spooner

Chris Spooner is a designer who loves experimenting with new web design techniques collating creative website designs. Check out Chris' design tutorials and articles at Blog.SpoonGraphics or follow his daily findings on Twitter.

41 Comments

  1. Sam says:

    In fact you can use a lot of these tips just for general web development anyway.

    Nice article and nice images to go with each point.

  2. aditia says:

    very nice article, for deleting revision post, i'm using wp-optimize plugin,

    btw how to measure when a blog need a cache plugins??

  3. Mamaduka says:

    Thanks, Chris great article.

  4. Michiel says:

    Great tips, thanks!

  5. Good article Chris, I've just got rid of post revisions and will try out a few of the other tips – thanks.

  6. gSvoren says:

    Very nice insight. I've followed several of these steps before reading this article, but I picked up a few handy tips!

    Thanks.

  7. Hi Chris,

    great article and very usefull, thanks for sharing! Disabling Post Revisions was new to me, so thanks for bringing that up!

    Cheers & Ciao ..

  8. Philip Brown says:

    Great post Chris! You obviously have a lot of experience in running efficient blogs. This kind of knowledge is invaluable to us mortals of the blogging world :)

  9. Luc says:

    I'd add Quick Cache to the list of caching plugins – none of the others work well with multi-site and domain mapping (using Networks+ specifically). Quick Cache solved my headaches at the weekend on a re-launched blog network – it doesn't have all the options that W3TC does, but it's reduced my VPS node usage by a factor of 10…

  10. Jason says:

    Well, once again beating me to another useful article.

    Currently writing 3 posts:
    WP Plugins: For the Benefit of…
    The Client
    The Site

    Combined they include points 1, 4, 5 and 9.

    Plugins – the Sloppy Truth… concerns point 2.

    Many thanks for the revisions thing (point 6), being a concern of mine for a few weeks and couldn't find anything decent to help me.

  11. Martin Lucas says:

    Great blog post, thanks. Going to save this for later and implement some of these on my own site and my clients' sites too.

  12. heathquinn says:

    Fantastic article. Thank you, Chris.

  13. Great suggestions, Chris.

    I would like to turn off revisions, as it annoys me to see that big list of stored versions at the bottom of my page. However, does that turn off the auto save feature, or are those unrelated? Auto save has preserved my work more than one time.

  14. I must say that I am not such of a WordPress fan. I believe that Blogger is better. However, you have presented some good things here. Thanks :)

  15. Thanks for a wonderful resource Chris. I've just gone and done Step six "Disable post revisions" and it works really well.

    Ill be implementing the rest when time permits :)

  16. Geeee says:

    Great post Chris, I've really enjoyed this post with great tips. By the way, I found useful plugin that can delete post revisions instead of disabling it completely; plugin called Delete-Revision and can be found here: http://wordpress.org/extend/plugins/delete-revision/
    Thanks again :)

  17. Chris Ross says:

    Chris, this is a great post! Thanks a lot. Getting some raw power out of WP is the hardest thing to do with the platform.

  18. Ben Stephan says:

    Great article… I turned off post revisions, deleted old plug-ins, and I already had a minifier active.

    One question, how do you optimize the database manually? Any other recommended reading or tips? Thanks.

    Again nice article.

  19. Rednights says:

    I noticed that Twitter Button and Facebook Like both download like 10 KB + 32 KB CSS files and 50 KB + 130 KB JS files …

    Is there a way to deal with this?

  20. Larissa Mac says:

    Some great suggestions here Chris.

    Nice work, I do try and follow theses unwritten rules, but sometimes get lost in the design and plugins requested by my clients.

    Keep it buzzing :)

  21. Its was nice post…
    thanks for sharing

  22. Hey, thank you for the nice post. I was searching around to get some valuable tip to speed up my site. I hope it will be useful. I will definitely apply these on my site.

    Thanks

  23. Ashfame says:

    Hey there!

    Just wanted to bring it up that your method of deleting post revisions is incorrect.
    I have written it at my blog a while back. Have a look :
    Correct method of deleting post revisions – http://blog.ashfame.com/2010/04/handling-wordpress-post-revisions-correctly/

  24. Nice tips. WordPress really awesome CMS. Specially for blog wordpress is great. Very effective plugin's are free to use like WP Super Cache or Akismet. Very simple and well defined coding makes wordpress so popular. Chris Spooner, i am huge fan of you. Thanks for sharing this wonderful post. :)

  25. Reece says:

    Great article, Must agree with the excessive use of widgets.

  26. Pritam says:

    I tried disabling Post Revisions as suggested by Chris, but it didn't work. According to WordPress Codex, the code has to be added to wp-settings.php file. It worked that way. (http://www.speckygeek.com/?p=452)

  27. Dewang Mistry says:

    Hey! Great post. I'll definitely implement these things on my blog. Btw what did you use for making these diagrams? They look really cool!

  28. SiewShuen says:

    thanks for sharing these tips. now it's all about speed. potential clients might leave just cause they can't be bothered to wait. will follow your tips :)

  29. Mirko says:

    Wow, great post. Chris you are not only good designer, you're also excellent WP developer.
    Thanks for tips!

  30. Hatch says:

    The advice to get rid of bloginfo is just bad. Read the following:

    http://cyborgsquirrel.com/2010/09/five-failed-wordpress-speed-hacks/

    Basically, bloginfo queries a bunch of data the first time it is run, and then just references that each additional time. Unless you remove them all, it's not really worth doing. And bloginfo is everywhere.

  31. Sandy Allen says:

    At the risk of *adding* a plugin, those those that are not ready to take the plunge on revisions should consider the Revision Diet plugin.

  32. Koren Berman says:

    Good post. What inexperienced WP users don't realize is that piling up plugins can not only result in slower loading times, but also security holes; as plugins have full access to the application, and if one is not coded properly it can jeopardize your entire infrastructure.

    Implementing a caching mechanism is fantastic to avoid multiple DB queries on each page. Moreover, I'd encourage to store important, such as your site name, in a constant instead of querying the DB for it every time. You really have to dig into your theme's files to understand how many redundant queries are being made.

    Btw I'm pretty sure (or at least hope) that get_bloginfo indeed caches the data it retrieves in a constant. It'd be great if someone could ascertain that.

  33. Great article, very useful info!

  34. Awesome article! All of this info is very helpful. Thanks!

  35. This is a MUST-READ article. Thank you very much! :)

  36. samuel says:

    Great tips Chris!
    I have a question about minify: in the settings of the w3 total cache plugin wich is the criteria on selecting wich js files embed and where, and with the CSS how can i select the template?
    Thanks

  37. Nice and much useful article Chris Spooner. M a great fan of yours. And gets much inspiration from your work.
    Keep it up.

  38. Joshua says:

    Chris,
    I've been looking for a way to ID unused custom CSS Divs. Do these effect speed?

    Thanks,
    Joshua

Sorry, comments are now closed