Optimizing WordPress Blog for Speed
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
- Compressing CSS & Javascript – Code Beautifier is the online tool which can produce best result when compressing css. It can apply shorthand notations, reduce unneeded text, merge selectors, compress color codes and font properties, removes backslashes & new lines and even discard invalid properties.For Compressing Javascript, there are lots of compressors like Minify Javascript, YUI Compressor, Dojo Compressor and JSCompress. Each compressor has its own way of compressing. Use any one which suits you.Using WordPress Plugins – Now if you don’t want to waste time to compress things manually, I suggest using Web Optimizer Plugin or Autoptimize plugin for WordPress. It can do everything related to speed up the front end including compress CSS, compress JS, move all CSS to 1 file, move all JS to 1 file, caching of site, compressing html, image compression and even can optimize your vps wordpress installs.
There are other plugins too for compressing namely: Script Compressor – for JS and CSS, WP-JS – for JS, WP-Minify – for JS and others like WP-HTML-Compression and GZippy.
Using too many compressing plugins may slowdown the site due to conflicting nature. Make sure you use only one plugin for each process of compressing. For example using 2 plugins both of which compress CSS can be detrimental and may not produce the required effects.
Note: Javascript should be loaded just before closing body tag and css should be loaded in the head tag for optimum performance.
Note: Here is another small tip. If you can shift all css and javsascript into single files and then compress them, your speed will increase manifold. But don’t try combining jquery and mootools type framework scripts. It can be messy.
- Compressing Images – Images contribute a lot to the size of the page of your site. You can compress images via 2 methods. First method is to directly edit a image in your favorite image editing program either by lowering its resolution or colors or by changing it to gif/jpg format. Second method is to compress the images on the fly using Smush.it from Yahoo. Smush.it is available as a plugin for wordpress. It compresses the images automatically and loads the optimized images.
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
-
- Cleaning Unused or Not required Widgets – Analyse each of your sidebar and footer widget/areas carefully. Is the widget/code really adding value to the site? Is it really required? For example, some sites have detailed archive and sitemap pages and still display archive links in sidebar which take up screen space and does not add value. Some sites try to add images of almost all blog directories they join. They don’t realise that it can add too much to the page load time and is not useful at all for the user. Avoid such pitfalls which can drive visitors away from your site.
- Reduce Comments Displayed – Sometimes some popular posts in a blog get almost 500-1000 comments. Imagine loading all of them on a single page. For most users, it can be a big delay in loading the page and people may not even reach the comment form if its placed after the comments. So you should split Comments into multiple pages. WordPress 2.7+ supports this. Go to Settings>>Discussions in your dashboard and select Break Comments into pages and also select the number of comments to display per page. 20-50 comments per page should be ideal. If you have lots of comments in your posts, you should display last page displayed since people will see newer comments at top.
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:
- Options Table – WordPress stores its settings in wp_options table in your database. Now the problem is that almost all plugins and some themes stores their settings in this table but don’t clean the entries when they are deactivated/uninstalled. To find such orphaned options and to remove them, I recommend using Clean Options or WP Options Manager plugin.
- Remove unneccessary Database Tables – When you deactivate plugins, they do get uninstalled but they don’t remove all settings from database. You sometimes need to remove them manually. Follow this step only if you know what you are doing and do make a backup of Database before doing any such thing. Some plugins create separate tables which can be easily recognised with their naming. You can easily drop those tables provided you know which table you are dropping.
- Revision Cleaning – Starting with WordPress 2.6, every time you save a post, a revision of it is created automatically in the database. Now its a good feature if you want to revert back to some version but sometimes it can easily bloat your database because a new revision is still created even if nothing was changed since last revision. (Note: Autosave feature of WordPress does not create a revision.). WordPress provides ways to limit the number of automatic creation of revisions created or disable them completely. To limit the number of revisions, open wp-config.php file and paste the following line:[sql light=”true”]define(‘WP_POST_REVISIONS’, 3);[/sql]Change number 3 to whatever you need to limit its number. If you want to disable the revisions completely, replace ‘3’ with ‘disable’. Now what if your database has already lots of revisions already. To delete all revisions, just execute this sql query from phpMyAdmin or whatever SQL Software you use:
[sql]DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = ‘revision'[/sql]
Change wp to your custom database prefix if you have done it (You can check my last tutorial of securing wordpress on how to change your database prefix).
- DB Cache – I already told you about caching the frontend using Cache Plugins but the database queries can also be cached and saved for future runs. Use DB Cache Reloaded plugin to cache your database queries.
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.
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 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.
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.
Super awesome tips Navjot !
Awesome tips!!! Thanks, Navjot Singh!!!
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.
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
Thanks to everybody for the wonderful comments. Good to see that my tips are working for you.
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
Is da article really orginal? Seems it is very much inspired from here http://www.wpbeginner.com/wp-tutorials/18-useful-tricks-to-speed-up-wordpress-boost-performance/
@ 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?
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.
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.
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?
nice its very great.. let’s try your recomment pluin.. 🙂
what is most recommeded wordpress plugin for sitemap.
Gr8 article, very well written and useful.
btw Web Optimizer is now WEBO Site SpeedUp.
great tips! very complete and well delivered. I guess this post is worth to bookmark.
Thank you very much it help me a lot!
Well I just got a text message from my girl friend that she broke up with me! Bad news for me but great for you. Just go to http://www.gf4free.com/members/surferdude23/ Enjoy!
[url=http://www.gf4free.com/members/surferdude23/][img]http://www.gf4free.com/members/surferdude23/uploads/9.jpg[/img][/url]
haha, love it. Don’t blame yourself.
I think this article was inspired from here: “How to: optimize wordpress blog for maximum speed” http://www.intenseblog.com/wordpress/optimize-wordpress-speed.html
Pingback: Optimizing Wordpress Blog for Speed | WPWebHost | Intenseblog.com
Wow great article on how to Optimize my WordPress website I must really thank you for this tips it helped me a lot.
Thanks we desperately needed this one ‘1.6 Prevent Hotlinking’
.-= JobGraphs´s last blog ..ERP Softwares =-.
One more thing, I would like to add to upload images effectively and save hosting space, See
http://www.techbrij.com/105/wordpress-tips-to-upload-images-effectively
Pingback: Intense Blog
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 =-.
Great Tips! Awesome, I would definitely try this tips to my sites!
Thank you!
.-= Readings´s last blog ..European Weekly Horoscope – September 11th – September 17th- 2010 =-.
Brilliant post,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.
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!
finally i got what i am looking for thanks mate
cheers 🙂
Hello, many, many thanks for taking the time to share.. It was useful for my team. Thanks for all of your hard work!
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.
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.
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…
Thanks for advices 😉 great article
Thanks for these advice. I need to speed up my blog.
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?
well, these is i absolutely needed! u rock guy to share your knowledge
Hey. I used your tips to optimize http://www.metal-head.org and it worked ! thanks a lot 🙂