Optimizing WordPress for Speed
I have already talked of maintaining your blog by implementing security tips in Securing your WordPress Install the Foolproof way. But maintaining your blog not only refers to keeping it secure. It also means optimizing your blog to the full extent so that end user experience on your blog can be improved and your blog’s speed can be improved.

The Optimizing process I will discuss here need not be done every day or every week. These procedures are to be done once every few months since doing them frequently won’t give you much of a performance enhance. I am listing the methods in two portions – one to speedup the frontend area which users see and the backend portion which is the Admin Dashboard.

Note: I am not listing here methods which are specific to VPS and Dedicated type hosting. They are out of the scope of this tutorial.

 

1. Optimizing Frontend

Somewhere down the line, you find that you are loading or showing some code to your visitors which is unnecessary or not useful but still adding overhead to your page loading. It can include unused widgets/unused javascripts/unused css code or broken links/code. To clean out this, you need to browse your blog, check its loading time and analyse which script or css file is loaded for what purpose.

 

1.1 Compressing Data

 

1.2 Reducing PHP Queries

If you analyse your wordpress theme files, most of the code is generated dynamically including your theme files path, css path, image path, rss feeds, comment feeds, html encoding, blog title, blog description and lots of other code. If you can replace the codes with their values, lots of php queries can be saved. This post will become too long if I explain all such tags and their replacement so I would suggest reading this wonderful post by ProBlogDesign for more on this.

 

1.3 Reduce Page Size

Paginating Comments

 

1.4 Caching Frontend

Each time your blog gets loaded, complete php code is run. On a fast hosting, this may not seem a big deal. But when your post gets instant viral traffic, lots of visitors try to access your blog at the same time and server may not handle the load easily.

To avoid such problems, you can cache the output of PHP Scripts in a HTML File which is served to your blog visitors and these static files load much faster since there is no overhead involved relating to running the code. This cache is recreated every few hours depending on how frequently you update your blog. For Caching you can use plugins like WP Super Cache and Hyper Cache. And do check compatibility issues of cache plugins with other plugins on your blog.

 

1.5 CDN (Content Distribution Network)

CDN is a technique where you serve content of your website(mostly multimedia items) from different servers around the world instead of a single webhost. This helps in distributing the load on your website equally among lot more servers and helps in loading your website at much faster speed than normal. I would recommend you to use Amazon Cloudfront service along with their S3 Service for this. You should shift all images, css files, javascripts, videos and any file which you offer for download to Amazon Cloudfront service or any CDN Service you use. Amazon S3 is just a hosting service for hosting your content but their Cloudfront service is the actual CDN Network.

You can either use S3 or use both to host your content. There are few plugins which can help you in this regard. Use Simple Amazon S3 Upload form plugin to upload files directly to S3 bucket from your WP Dashboard or use Amazon S3 for WordPress Plugin which automatically uploads your wp files to S3. I cannot explain the complete procedure of working with CDN here so head to Inquisitr for more on Amazon S3 and CDN usage along with WordPress.

 

1.6 Prevent Hotlinking

Sometimes other websites link to images and other multimedia content on your site directly and can crash your server directly or indirectly. To prevent this, you need to disable Hotlinking. Put this code in your site’s .htaccess file:

[html]
Rewrite Engine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www.)?YOURDOMAINNAME.com($|/) [NC]
RewriteRule .(gif|jpg|jpeg|png|mp3|mpg|avi|mov|flv)$ – [F,NC]
[/html]

You can add more file formats if you like.

 

1.7 Prevent Content Scrapers

Content scrapers or Bad Bots just scan sites and scrap the content to display on their own sites. They just keep hogging the bandwidth of your site with no real purpose. You can block such bad bots and scrapers using various methods like Implementing .htaccess blacklists and by blocking sensitive areas of your site by using Robots.txt. A sample robots.txt for a wordpress install is mentioned below:

[html]
User-agent: *
Allow: /wp-content/uploads/.gif
Allow: /wp-content/uploads/
.png
Allow: /wp-content/uploads/.jpg
Disallow: /wp-
Disallow: /search
Disallow: /?s=
Disallow: /feed
Disallow: /comments/feed
Disallow: /author/
Disallow: /useronline/
Allow: /feed/$
Disallow: /
/feed/$
Disallow: //feed/rss/$
Disallow: /
/trackback/$
Disallow: ///feed/$
Disallow: ///feed/rss/$
Disallow: ///trackback/$
Disallow: ////feed/$
Disallow: /
///feed/rss/$
Disallow: ///*/trackback/$
[/html]

You can also use AntiLeech Plugin for WordPress to ward off spammers and feed scrappers.

 

1.8 Load only when needed – Use WordPress Conditional Tags

Plugin and theme authors have a bad habit of including all javascript and css into header without even adding checks to load them only when required. Each plugin’s file gets loaded on every page of blog which can make things slower. I will not explain this method since it will be difficult to explain it entirely here and moreover this will require hacking of plugins and themes so I will just point that using conditional tags of wordpress alongs with proper hooks and filters can make a blog faster. If you are comfortable hacking a core plugin/theme or if you are a plugin/theme author then please take a look at posts by Justin Tadlock, White Shadow and Coen Jacobs for more information on this.

 

2. Optimizing Backend

In Backend the scope of cleaning mostly refers to deactivating unused plugins, finding proper replacement plugins for non working ones and cleaning the database of your blog which can become bloated over time.

 

2.1 Cleaning Unused Plugins

Go to your Dasboard>>Plugins and go through all activated plugins and check whether you really need all of them. I have heard from bloggers that they have over 50 active plugins. Each plugin needs to be executed during the loading of blog and some are loaded even when you are logged in the Dashboard, so each new plugin adds a bit of overhead to your server/webhosting. So deactivate or delete the plugins which you know you will never need/use in future.

 

2.2 Database Maintenance

WordPress Database can become bloated sometimes if not maintained properly and can create problems if you have a big blog. You should use WP-DBManager Plugin to auto optimize Database at set intervals. But optimizing a database does not mean running the optimize command on your db. There are other areas of concern which can make a database bloated listed below:

 

2.3 Reducing Pings List

Normally WordPress provides you with a default service to be pinged everytime you publish/edit a post which is Pingomatic. But some webmasters prefer to ping more services and in the process expand the list too much. This increases the load on your server whenever you publish/edit a post and may slow down the posting. Reducing that list to a optimum of say 5-6 services should be enough. So choose your ping list wisely. Ping List is under Settings>>Writing option in your Admin Panel.

A Really Long Pings List - Not useful

 

2.4 Google Gears

WordPress now has option of speeding up your Dashboard using Google Gears. Gears enabled wordpress to store all static files on your pc and your dashboard loads faster if you enable it.

Enable Google Gears

Enable Gears for your wordpress by visiting Tools>>Enable Gears in your WordPress Admin. When you click on Enable gears, it will show a popup stating that whether you trust that site to use gears.

Activate Google Gears

Enable the checkbox and click Allow. Then it will start updating the files from your hosting to your local PC and now your site will be gears ready. Though Offline Post Editing/Writing is not possible via Gears on WordPress.

 

3. General Suggestions

Upgrade WordPress, themes and plugins regularly from time to time. Choose your webhost wisely. If you install Apache, PHP and MySQL yourselves on your hosting, then keep them upgraded to avoid potential problems.

42 Responses

  1. Thanks Navjot for such great article. From past few days, I have been working on improving site speed and couple of times my blog even crashed. But right now it’s working fast and I have used Page Speed from Google to analyze it which has shown good results.

    I am right now using Web Optimizer plugin which is way better than WP Super Cache. I suggest everyone to try it and experience your faster wordpress blog.

  2. Thanks Navjot for this lovely and really informative post.
    I’ve been using wordpress for a long time and I research a lot on internet on how to speed up my blog. I must mention that most of the plugins you have mentioned are already installed by me, but I never considered optimizing PHP queries and database and preventing hotlinking. Now when I’ve tried these, the results are amazing. I’m really happy with the speed of my blog now and moreover the optimization was completely free. Thanks a lot for such a useful post. Hope to see more posts from you.

    With Regards
    Ajinder

  3. I just find U in one of my google ads spot inside my webpage, this post is incredible, it will help me a lot, since I have several blogs which are slowing down form time to time, I ve tried some tips , but didnt knew there where so many options available.
    Thanks

  4. @ Wp Beginner
    Really, it seems pretty same. Seems the article is interpreted in his own language and some points are removed. It’s not inspiration, it’s copying and alteration.
    By the way, are you the administer of WP beginner?

  5. Nope…my article was not inspired from there. Infact I took a complete different approach by separating the optimization process into backend and frontend. And I have provided way more tips than those 18. And somewhere some tips can be common because they are the actual optimization tips to speed up wordpress.

  6. Hi Navjot.
    By breaking up the optimization process into backend and frontend doesn’t prove anything. And the tips other than those 18 are mere common tips. The article at WPbeginner provided tips which are somewhat above the basic techniques and you might have added the basic part to it. Whatever the truth be, both the articles seem similar, and not to mention useful to me. And I said both of’em.

  7. is it recommended to store repeating functions results in variables?

    For example, if I have the_title() or the_permalink() functions appearing more than once in my index.php.
    Will it be faster if I type and then echo $title1?

  8. Pingback: Intense Blog
  9. Excellent list. I’ll have to go back and re-read it again and see what I can do to speed up my blog. I am not a fan of plugins loading all their files when they aren’t needed. I’ll have to examine my blog to see what unnecessary files are loaded for each page.
    .-= Paul´s last blog ..Speed Up Your Web Site By Using CSS Sprites =-.

  10. amazing and just what i need to lessen my worries in any hosting account I have right now. Very complete and easy to follow great job and thank you very much for sharing!

  11. Some really great tips here. Going to try the hotlink .htaccess code. Currently use Bluehost as hosting server and have noticed that bandwidth has been increasing.

  12. I ve tried some tips , but didnt knew there where so many options available.
    I was need help how to develop wp blogs, I got good help from your this article, thank you for keep updating and helping to us.Some really great tips here.

  13. As a newbie in blogging, your post really helped me a lot. After following your instructions step by step, my blogs are now more efficient and faster. Thanks for sharing your knowledge! You’re a blessing…

  14. Thanks for the great tips. I tried them along with some others from different articles and have been able to bring page speed score to 94. But still it is not as responsive as i would like it to be :). I guess wordpress by itself is slow. What is the best performance number/page download time anyone has experienced using wordpress?