WordPress is one of the most popular blogging and CMS platforms to date.

What makes it unique is the fact that it satisfies the needs for both start-ups and very serious bloggers and businesses. The community is world class and you can get a very professional CMS and endless functional extensions for free.

WordPress sets new standards when it comes to support for building templates and it so easy to get started with and still so powerful that most people won’t let it go even if they run into serious success. Some of the really high traffic blogs out there run on WordPress! ex smashingmagazine, mashable that both have millions of hits every month.

But let me be honest with you – if your blog becomes just remotely popular you wont survive a standard out of the box WordPress deployment.[exec]$filestr = file_get_contents(‘http://www.tripwiremagazine.com/googleadsensebelowmoretag.inc’);
echo $filestr;[/exec]

Flexibility, ease of use, etc. comes at a very high price and in fact WordPress consumes enormous amounts of CPU and memory resources in order to respond to a single page request. The many string replacements in templates, multiple request to the database per request simply adds up and may take your entire site down if you hit the front page on fx. digg.com. Of cause you can just buy more hardware but as most bloggers don’t have budget for that it is important to get as much as possible out of the hosting plan you have. For good order I would like to state that my experience tells me that if you start getting moderate traffic ex. more than 2500 hits per day then you have grown out of any shared hosting solutions no mater how much you optimize your WordPress installation! I learned this the hard way and ended up changing to a Hybrid VPS at Wired Tree. After experiencing the regular frustrations using a shared plan at bluehost.com (servers down, slow, account closed because of too much CPU usage etc. ) is one of the best experiences I have ever had as a blogger, seriously! I will not cover hosting any further in this blog as it is a subject of it own. Let’s investigate some essential tips you can use to improve you WordPress performance.

Measure load time for future reference

Before we optimize anything I would recommend that you collect a few measurements that you can use as reference to see if your actions to improve performance have been worth the effort. Take multiple measurements and if you have the time and patience try making measurements over a few days with varying load. Also keep in mind that plugins and themes are software and in some cases they may not be optimized too well. I recommend that you go for using premium wordpress magazine themes for my sites, also to get the support.

Option a) Goto this on-line speed test tool (or use similar) and make a few hit on your site. On-line services like “iwebtool Website Speed Test” is one way to get a measure but I would recommend you to use a client side tool as well to get a better picture of your actual performance.

wp-performance

Option b) Use YSlow for Firefox to analyse your template complexity, size and load time from a realistic client. The load time and size can be found in the lower right corner. The Yslow Grade will be covered later in this post but is worth investigating!

wp-performance

Optimization Tips

#1 – Use serious caching (impact: very high)

There are many ways to do caching in WordPress. I’ll be honest with you – I have a favourite way to do it! If you are not using WP Super Cache Plugin already this is the time to make the change. It generates fully static html files when your pages are accessed for the first time and these are then served directly by Apache without processing PHP scripts on subsequent requests. When you read on to the other tips below you will know why this is so important. Providing static cached html files as you will do with WP Super Cache Plugin is the single most effective performance optimization tip I can give you BUT it is not without problems. Some pages will contain dynamically generated content and you want your updates to pages to be visible to you readers instantly. So when serving static cached html you need an intelligent and very well integrated caching engine and that is just what I believe WP Super Cache Plugin is providing.

wp-performance

WP Super Cache Plugin serve static pages only to:

  1. Users who are not logged in.
  2. Users who have not left a comment on your blog.
  3. Or users who have not viewed a password protected post.

Those users who don’t see the static files will still benefit because they will see regular WP-Cache cached files and your server won’t be as busy as before. If you have plugins or other dynamic elements on your pages that need to be executed on the server on each request WP Super Cache provides a way to get around this. You can find a guide here in the section “How do I make certain parts of the page stay dynamic?”. You can also consider to use Javascript to load dynamic content fx. if you have a recent comments widget.

#2 – Optimize your template by reducing number of requests to the server, to the database and by lowering the overall load size (impact: very high)

Minimize simple unnecessary PHP queries. I’m a great fan of premium themes because they are so flexible and simple to adjust to your own needs. I also have found that flexibility is costly in terms of performance. To give you an example: searching for “bloginfo” in freshnews theme from Woothemes (the one I use) returns 283 results. What does this tell us? It tells us that functions like “bloginfo(‘name’)” and “get_bloginfo(‘template_directory’)” is used intensively. In some themes get_option() is also used heavily and will also be costly for rendering the page in the server. In the theme I have 961 of these… If you have cached your pages as described above this will only impact the first request where a page requested is not already cached. If user experience for all users (including the few who hit a non cached page) then it is highly relevant to see if you can get rid of any unnecessary PHP queries.

How to: ex. <?php get_bloginfo(’wpurl’); ?> just replace it with your wordpress installation URL.

Reducing requests to the server is key. Combining css files into one big css file can make a difference (One 50kb file loads a lot faster than five 10kb files). If you installed YSlow earlier to test performance you may have noticed that it also analyse the page and provide input on how you can optimize it. Having 17 Javascript files and 11 CSS files as illustrated below and a total of 75 components tells you that this page can be optimized! Looking at the Grade tab will help you understand what you can do to improve the load time.

wp-performance

There are several thing you can do and I would recommend that you read this article Best Practices for Speeding Up Your Web Site if you want to squeeze a few more milliseconds out of your load times. You will find concrete ideas for how to minimize number of requests to the server without compromising your design. Fx. combining CSS and Javascript into fewer files, using CSS Sprites to load fewer images etc. WP CSS is a plugin that may help you reducing number of requests to the server.

Load some Javascript in the footer. Some call it the The golden rule – CSS on top, javascript on bottom. In some cases you may want to put links to Javascript to the bottom of the page ie. just before </body>. Why? Because first priority is to render the page to the user and not downloading large scripts that are not instantly needed. This does not apply to all scripts and the key ones required by other scripts (e.g. libraries like jQuery) are still to be placed in the header. Also don’t move scripts that that provide Javascript functions used inline (e.g. a onclick=”doSomething()” as these would fail if the user interacts with elements before the function is available.

Make sure proper caching headers are set. Expires HTTP header can be set to specify a expire date on items downloaded from your site so that browsers won’t try to re-fetch images, CSS, javascript etc files that haven’t changed (this reduces the number of HTTP requests) and hence there will be a performance improvement on subsequent page views. You can learn more about controlling the expires HTTP header in .htacces in this article. How to Add Far Future Expires Headers to Your WordPress Site

#3 – Keep you database clean (impact: high)

Every database will, over time, require some form of maintenance to keep it at an optimal performance level. Purging deleted rows, resequencing, compressing, managing index paths, de-fragmenting, etc. is what is known as optimization. MySQL builds up what is called overhead and it will degrade your performance over time if you are not actively taking care of this. For good order you need to backup your database before the optimization procedure.

wp-performance

There are more ways to clean up overhead and repair your MySQL database. If you don’t have any database tools except for phpAdmin that most will have access to through their cpanel hosting admin interface. The phpAdmin way is rather simple and it is a tool you should be familiar with anyway. On the other hand it requires you to log into a separate tool and it would be much easier if you could do it all from WordPress – and you can. WP-DBManager is the perfect alternative and lets you do the database operation most WordPress user need including backups. It allows you to view current status of the database, optimize, repair, backup, restore, delete backup, drop/empty tables and run selected queries. Supports automatic scheduling of backing up and optimizing of database. Backing up and optimizing is as simple as clinking one button.

wp-performance

wp-performance

After running optimize all of your tables should have zero overhead as shown here. Check it once a month and run the job again when overhead starts building up.

wp-performance

If you are just like me – a bit lazy you may want to schedule all of this to happen automatically. In the DB Options tab you can configure this.

wp-performance

#4 – Proper image hosting can be important (impact: high)

Serving files to browser clients consume significant CPU resources on your web server. If your site is really busy you may free up a lot of CPU by moving images, CSS, JavaScript and other static files to a storage service like Amazon S3 Storage service. Try reading this step by step guide if this is something you believe your site will benefit from. Amazon S3 is not exactly free but it will serve your static resources fast and reliably. At the same time I will bet that your overall solution will be more scalable and the extra cost for Amazin S3 may be earned back by lowering the costs of your web server hosting.

wp-performance

#5 – Enable WP Built-in Object Cache (impact: medium)

WordPress introduced a file based caching of php objects in 2.x versions. It caches recurrently used php objects thereby reducing MySQL calls and improving performance.
It is currently disabled by default. You can enable it by adding the following to your wp-config.php:

// Enable the WordPress Object Cache:
define(ENABLE_CACHE, true);

This can give an immediate and measurable performance improvement. On the other hand it will increase the memory usage and you should be careful about using this on a shared hosting plan.

#6 – Turn off/limit/clean up post revisions (impact: medium)

Post revisions are important if you work together with others to create posts. It is also a good way to make sure that any changes to a post is documented and that something you have been working on for some time is not lost. On the other hand revisions can be a serious waste of database and server resources. Number of revision for a post can be found below the editing area.

wp-performance

To prevent the post revision from cluttering your database, it is an option to turn it off once and for all. You can easily turn off post-revision by adding the following line to the wp_config.php file (needs to be between the <?php and ?> tags.

define(’WP_POST_REVISIONS’, false);

This is that hard way and I would recommend another approach that prevents you from loosing any work if you fx. by accident save something wrong onto a document you put a lot of work into. You can keep a limited number of post revision saved per post. In your wp_config.php file, add the following line instead:

define(’WP_POST_REVISIONS’, no_of_revision);

and replace the no_of_revision by the number of revision copy you want to keep.

If you used revisions for a long time and have hundreds of posts with 10+ revisions each you may want to consider cleaning this up and using  the delete-revision plugin is a good option. It has not yet been fully tested with WP 2.8.6 but I have tried it as par of my preparations for this post and it worked fine.

wp-performance

#7 – Always keep WordPress and plugins up to date (impact: medium)

The developers maintaining WordPress are serious about their jobs and do a great job. Therefore it is recommended to plan an update  as soon as WordPress informs you of a new release. With regards to upgrading performance may be the least of you concerns. Security is usually the top priority so even if your site is fast you should not wait too long with upgrades. Make sure to follow the backup advice in #2 before updating WordPress. Using the WordPress build in updating feature have worked fine for me every time. Just make sure that if you make any changes to core files in WordPress (even though you should not really) then updating this way will instantly overwrite your changes. Backing up your files and keeping track up custom changes is important in that case.

When it comes to plugins you should be very careful. Installing and activating a plugin that is not downloaded from wordpress.org may be a direct thread to you WordPress installation. Also make sure you check if a plugin is well rated (3 or more stars) on wordpress.org before using it. Some plugins are written by inexperienced programmers that may not have thought carefully enough about security and performance. It is important to do some investigations before trusting a plugin and to monitor your site performance carefully when new plugins have been installed. Believe me I have tried to have my account closed in my early days as a blogger because I activated a plugin that went bananas after a few days of operations because it used bad bad practise when querying the database.

#8 – Remove unused themes (impact: minor)

There is no reason to have a lot of unused themes on the server, delete those that you don’t use.

#9 – Disable and Delete unwanted plugins (impact: minor)

If you have decided that you have no use for a particular plugin, deactivate them and delete them from your server. The more (unused) plugins you keep in your server, the longer it takes for WordPress to generate the plugin list and the higher tendency that it will slow down the loading time of your blog. Simplest way to delete a plugin is by using the “Installed Plugins” page. Any plugin that is not active will have a delete button. Be aware that deleting a plugin this way will not clean up the database tables it used.

#10 – Delete spam comments (impact: minor)

If you get a lot of spam comments you should not leave it in the database. Make sure you delete it as it comes in. If you want to use a plugin to make cleaning up easier I can recommend WP-Optimize. It allows you to delete all spam and unapproved comments and provides a lot of other useful optimization features.

wp-performance

#11 – Check your site for dead links (impact: cosmetic)

In the blogging sphere linking to relevant content on other blogs and websites is common practice. To keep your posts relevant and useful you should check frequently that the linked post/domain still exist and you are not left with a dead link.

The broken link checker plugin checks your new article for broken links as soon as it is published. It also scans your old posts when you are logged into the Admin page. Any broken links found are reported to you and you can choose to edit or unlink them from the posts. The first time I used this plugin I found more than 250 broken links on old posts.

wp-performance

References

WordPress Performance: Why My Site Is So Much Faster Than Yours – This post is worth reading if you want to go even deeper into the details of optimization. It covers things you can do with regards to MySQL Query Cache, PHP Opcode Cache, Apache httpd.conf, PHP php.ini and Linux Kernel.

 

Pin It on Pinterest

Shares
Share This

Share This

Share this post with your friends!

Shares
WordPress Appliance - Powered by TurnKey Linux