WordPress plugins, themes, tips and hacks

38 ways to optimize and speed up your WordPress blog

April 23, 2008 – 1:43 pm | by Miriam Schwab

WordPress blogs and sites can be notoriously slow. But fear not – here are ways to make your WordPress blog super speedy and fun for your visitors to view with a few tweaks, hacks and plugins. Be sure to check back because I will be updating this post as I discover new and wonderful ways to optimize and speed up WordPress blogs.

Matzah[This post is in honor of the current Pessach (Passover) season, a Jewish holiday where we clean our houses frantically in the hope that not one crumb of leavened bread (i.e. regular bread) be found during the 7 day holiday. This post is the WordPress version of Pessach cleaning, where cluttered databases are equivalent to leavened bread, etc. Happy Pessach!]

Define goals and create benchmarks:

  1. First, define a goal, such as reducing page load time from 8 seconds to 2 seconds.
  2. Measure your initial state and the results of each modification so that you can quantify any improvement. Test your site’s speed with the Website Speed Test, but do multiple tests since the results can be inaccurate due to fluctuations in your internet connection and other factors.
  3. Use Pingdom to get a detailed analysis of your blog’s loading time and performance.
  4. See what your browser is doing with tools like Firebug’s network tool, Charles Proxy or Wireshark, and review the server logs.
  5. YSlow – analyzes web pages and tells you why they’re slow based on the rules for high performance web sites. YSlow is a Firefox add-on integrated with Firebug. See this presentation from Yahoo! that covers their latest research results and performance breakthroughs. It covers their existing 14 rules, plus 20 new rules for faster web pages. They’ve categorized the optimizations into: server, content, cookie, JavaScript, CSS, images, and mobile.

     

    SlideShare | View | Upload your own

Reduce the number of dynamic PHP and http calls:

  1. “There is an inherent overhead in each HTTP request. It takes substantially less time to serve one 30K file than it does three 10K files.” So combine all files in a type into a library. Learn how here.
  2. Use different host names to increase the number of active download threads.
  3. Minimize PHP and database queries – Each time a page on your site loads, if your browser has to execute any PHP queries, it adds to the load time. If you replace the PHP queries with static HTML, every time a page loads, your browser just reads the HTML. An example from WP Candy:
    With PHP requests: <title><?php bloginfo(’name’); ?><?php bloginfo(’description’); ?></title>
    Without PHP requests: <title>WPCandy - The Best of WordPress</title>
    Joost de Valk says that you can remove 11 queries to the database by doing the following in your header.php and footer.php files:

    • making your stylesheet URL’s static
    • making your pingback URL static
    • making your feed URLs static
    • removing the blog’s WordPress version
    • making your blog’s name and tagline / description staticSee more examples of how you can replace code in your WordPress template files with static HTML here and here.
  4. Check if you have too many external calls to things like Amazon, eBay, MyBlogLog, etc. Try commenting them out one by one to see if it speeds things up.

Optimize your files: CSS, HTML, Javascript, images, video

  1. Optimize your image files for the web.
  2. Make sure that all images have height and width tags.
  3. Consider hosting your images on an external site like flickr that has huge servers and can handle the load.
  4. Use CSS sprites for static web images. CSS sprites are where the images are added to one larger image file, and laid out in a convenient way. Here’s a CSS Sprites generator.
  5. Do not host videos on your server. Upload them to YouTube, Google Video, or any other video sharing site and let them handle the server load.
  6. Compress your Javascript, using a tool or by removing formatting (and potentially by shortening function and variable names). This can reduce file size by 60%. Add gzip compression to that as well and you’re looking at a serious size reduction.
  7. Compress HTML and CSS by removing HTML formatting, white space (where you divide code among separate lines for easier readability), trimming class names, omitting unambiguous quotes around attributes, etc.
  8. Compress your CSS with the CSS Compress WordPress plugin – Automatically removes comments, new lines, tabs, and gzip compresses (GZIP) any CSS file called with “<?php bloginfo(’stylesheet_url’); ?>” Just activating the plugin with the default Kubrick theme will reduce the CSS file from 8k to 1.7k.
  9. Compress your CSS by using shorthand CSS. Here’s an example from WP Candy:
    Long: .test {margin-top: 7px; margin-right: 1px; margin-bottom: 5px; margin-left: 3px;}
    Short: .test {margin: 7px 1px 5px 3px;}
  10. Use external scripts – Instead of placing tons of code in your header.php file, use external scripts. This allows the browser to cache the script so it won’t have to read it for every other page.
  11. Validate your code at W3C to make sure you don’t have any major errors slowing down your page.
  12. Allow progressive rendering: Load CSS files at the top of the page, from within the head section; load JavaScript files at the bottom of the HTML. And/Or…
  13. Stop slow loading scripts from breaking your blog with IFrameWidgets v1.0 WordPress plugin. Slow widgets or snippets of Javascript can either time-out, or prevent the items below them from loading. The plugin creates WordPress sidebar widgets that run in an IFrame. Since IFrames load in parallel to the rest of the page, slow loading JavaScript widgets won’t affect the rest of the page.

Plugins

  1. Disable or delete unused plugins – some plugins have tons of script and code, and even create database tables in your WordPress database. Use only the plugins you really need, and delete the rest.
  2. Sometimes plugins require that you add a snippet of code to your theme’s template files to call the plugin. Usually, it looks something like this:
    < ?php refer_plugin(); ?>
    However, if for some reason you disable that plugin, you will get an error. Joost de Valk recommends using PHP’s special function called function_exists to prevent the blog from breaking if plugins are disabled or removed. Using it will make the code look like this:
    < ?php if (function_exists(’refer_thanks’)) { refer_thanks(); } ?>
  3. Control when your WordPress plugins are loaded: WordPress processes all of the code for all active plugins, even if that plugin isn’t used on a particular page. If a particular resource heavy plugin isn’t used on certain pages, then you can tell WordPress not to load it on those pages by wrapping an if statement around the content of each function to check what page is being loaded. Learn more about how to do this here and here.

Database

  1. Use phpMyAdmin to optimize your database: Log in to phpMyAdmin, select all the tables, and then “repair” and “optimize.”
  2. Delete excess records in your WordPress database. All plugins use the wp_options table to store data, which is the same table used by WordPress to store all settings for your blog, and is accessed every time you open any page. When you deactivate a plugin, these records are left behind, bloating your database. To clean it up you can use the WordPress Clean Options Plugin, which finds orphaned options left after you have removed plugins and removes them from the wp_options table, or manually as follows: Back up your database, login to phpMyAdmin, open your blog’s database, and click on browser for the wp_options table. Go through this table record by record to identify any records left behind by old plugins. (from WordPress Web 2.0 Spot-Er).
  3. Use the Optimize DB plugin to optimize the tables of your database.
  4. Use WordPress Plugin: Fix Database to check all tables in your database and fix any errors.
  5. Lester “GaMerZ” Chan’s WP-DBManager 2.11 plugin sorts your database backup files by date in descending order, can repair databases, and allows automatic scheduling of database backups and optimization.

Caching and protecting for server overload

  1. WordPress has a built-in caching system. Learn how to enable the default WordPress object cache. This has apparently been disabled in version 2.5.
  2. WP-Cache 2 – caches Worpress pages and stores them in a static file for serving future requests directly from the file rather than loading and compiling the whole PHP code and then building the page from the database.
  3. WP Super Cache – This plugin is a fork of the WP-Cache 2 plugin, and generates html files which are served without ever invoking a single line of PHP.
  4. PHP Speedy – PHP Speedy is a script that you can install on your web server to automatically speed up the download time of your web pages.
  5. Use the Expires and cache-control max age headers for all pages; Make dynamic pages support the if-modified-since request header; Use far future expiry headers on static resources; Use the cacheability engine to test that you have caching and validation set up correctly. If you don’t know what all this means, don’t worry, neither do I, but you can find out more here.
  6. Digg Protector plugin – The Digg Protector will determine if a visitor is from Digg, and if the visitor is indeed from Digg, the plugin will serve them a remotely-hosted version of the image. Otherwise, the plugin will serve the locally-hosted (on that server) image.
  7. Some more caching possibilities: MySQL query cache, PHP Compiler Cache. Learn more here.
  8. Configure Apache for maximum performance.

Happy Optimization!

Sources:

Speed up your website: Part One

How-to: Optimize your site for speed – really excellent article with practical tips

How to Enable the Default WordPress Object Cache – talks about wp-cache, wp-cache 2, and built in wordpress caching.

Digg Protector

4 Simple Ways To Speed Up WordPress

Speed up and clean up your WordPress!

5 Tips to Help Your Slow or Sluggish Blog or Web Site (Wordpress Especially)

Deleting excess records in your WordPress database

WordPress on Speed: 17 Tweaks to Accelerate your WP

The 3 Easiest Ways to Speed Up WordPress

WordPress Theme Hacks

Diggproof & Speed up Your Wordpress Blog

WordPress Optimisation: Control When Plugins Are Loaded

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
  1. 34 Responses to “38 ways to optimize and speed up your WordPress blog”

  2. By Ryan on Apr 23, 2008 | Reply

    WP Cache and WP-Super Cache are very good.

    I’m using them at the moment and they do make a noticeable difference. In particular they seriously reduce server load.

  3. By DanGarion on Apr 23, 2008 | Reply

    Just an FYI the built in Wordpress Object Cache option was disabled in 2.5. There is a way to enable it but it’s not really suggested by them to do that.

  4. By Miriam Schwab on Apr 23, 2008 | Reply

    @DanGarion – thanks for pointing that out, I wasn’t aware that the WordPress Object Cache was disabled in 2.5. I’ll make a correction in the post.

  5. By Blake Imeson on Apr 24, 2008 | Reply

    Terrific post! This is just what I have been needing.

    Not sure, but I suspect some of my sites are loading slower than they should. After reading this post I had 12+ tabs open of things to do/read. *sigh* Thanks!

  6. By Miriam Schwab on Apr 24, 2008 | Reply

    @Blake – I know. I’m in the same situation. Sorry to create so much work for you.

  7. By Susie Q on Apr 24, 2008 | Reply

    Hey, great tips- I’ll definitely install wp-cache sometime soon.

  8. By James Mann on Apr 25, 2008 | Reply

    This is an extremely useful post. My MMO wordpress blog loads pretty fast but I have other blog themes that don’t and I didn’t understand why. I am sure this post has everything I need to get them sped up a bit.
     
     

  9. By Marina HotForWords on Apr 25, 2008 | Reply

    Great article.  Quick question though, if I’m using wp super cache, do I need to do all those changes with the PHP calls as well?  Aren’t the pages cached with the super cache and therefore the php isn’t being called?
    In other words will it dramatically speed things up even thought the pages are cached?

    Thanks!
    Marina

  10. By Curtis on Apr 25, 2008 | Reply

    Great article, covers just about everything. And I’m glad my post gave you some info, and part two of that post is much more in depth.
     
    Marina,  WP Super Cache takes your files and creates a static HTML file so you wouldn’t need to remove the php.  And yes wp super cache dramatically speeds things up :)
     
     

  11. By Ryan on Apr 26, 2008 | Reply

    Marina – The caching plugins generate the HTML based on the PHP every time something changes on your site, so you can’t remove them. Without the PHP, there would be nothing to create the HTML! When caching is used, the HTML is stored, whereas when it is not on, the PHP generates the HTML every time the page loads.
    Also, (I think) they dynamically generate the page for anyone who is logged in or who has recently commented on your site.

  12. By Mosey on May 21, 2008 | Reply

    Thank you for an extremely helpful article! I’m only beginning to touch the iceberg by following the suggestions from step 1! However, I do have an issue at the moment with a 2.3.3 site that I run, because WP-Cache2 doesn’t seem to work on it (anymore?)  so I’m now forced to turn on the default WP caching, as I’m not sure what effect SuperCache will have on the installation.

  13. By Mosey on May 21, 2008 | Reply

    p/s: Sorry, I just wanted to add that GamerZ “Database Manager” plugin can be setup to automatically repair, optimise and backup databases periodically (e.g. daily) :)

  14. By Jacob Santos on Jun 2, 2008 | Reply

    The WordPress Object Cache removed the file based portions of the code. Before you could enable and disable whether it wrote/read from a file instead of using the database. That part has been removed. The WordPress Object Cache is always on in 2.5, unless you replace it with another caching plugin.

  15. By Ash on Sep 16, 2008 | Reply

    Thank you Miriam for taking the time to write such a wonderful guide for optimizing Wordpress.  I’ve recently installed the WP-Supercache plugin and its made a big difference in my performance.  I had previously intalled a plugin called WP-Wall (similar to a Facebook type wall) and it caused my hosting company to shut down my site due to CPU overload.  They suggested I install WP-Supercache and since my blog has been running much smoother.  I will also follow your advice about deleting the plugins I am no longer using.  This is something I hadn’t thought of.

  16. By Ryan on Sep 22, 2008 | Reply

    Ash – You probably already realised this, but I just want to clarify something in case you have misunderstood.

    You don’t need to delete plugins you aren’t using, you just need to delete plugins which are activated that you aren’t using. They don’t do any harm just sitting there, it’s only when you activate them that they become a problem as they start doing database calls, displaying random code in your pages etc.

  17. By JP on Dec 5, 2008 | Reply

    In the “Plugins” section above, you have a link to the following:

    http://wordpressgarage.com/wp-admin/Control%20when%20your%20WordPress%20plugins%20are%20loaded

    However this link does not work.

  18. By Tim on Dec 7, 2008 | Reply

    hmm.. what is the best ways?? I mean i tried using WP-Cache it seems the same and not faster, and i changed to WP-super cache, i cant change the htaccess files as my server is shared among a few sites.. if i change, it cannot be opened so that means rewriting htaccess files cant be done, so basically what is the best way?

  19. By Ryan on Dec 12, 2008 | Reply

    Tim – if you can’t modify the htaccess file then I think there is nothing you can do. You should get a better host anyway, as you can’t use proper permalinks without changing your htaccess file.

  20. By Ajay Kumar Singh on Jan 12, 2009 | Reply

    Excellent post, this is what I’ve been looking for. It helped me a lot to improve performance of my wordpress blogs.

  1. 15 Trackback(s)

  2. Apr 24, 2008: Ultime dal fronte WordPress 17-2008
  3. Apr 25, 2008: WordPress Weekly News, 17-2008
  4. Apr 27, 2008: WordPress is a CPU hog - use caching plugins! | WordPressGarage.com
  5. Apr 29, 2008: Caching enabled - kleines Update für Planet iQ » think twice & have fun!
  6. May 1, 2008: Fatih Hayrio?lu'nun not defteri » 26 Nisan web’den seçme haberler » Metin, alan?, de?er, önerme, i?ini, yard?m?, Ba?lant?, Javascript, için, anlat?ml?
  7. May 6, 2008: Come ottimizzare la velocità di caricamento di un blog wordpress | daniele rollo
  8. May 17, 2008: [ fatih hayrio?lu ]26 Nisan Seçmeler « CSS Ar?iv
  9. Jun 3, 2008: 38 ways to optimize and speed up your WordPress blog | Anidan Design : eco-friendly web & graphic design
  10. Jun 7, 2008: 25 formas de optimizar e acelerar o seu blog Wordpress | Fique Rico Online
  11. Sep 14, 2008: Optimize WordPress install and save webhosting dollars! | Blog Design Studio
  12. Nov 21, 2008: Easy Steps To Speedup Your Wordpress Blog : Cloud Four
  13. Jan 3, 2009: Caching enabled - kleines Update für Planet iQ - Der Webanhalter
  14. Mar 4, 2009: Poll result : 55% bloggers pay less than $10 on hosting! | Blog Design Studio
  15. Mar 6, 2009: Caching enabled - kleines Update für Planet iQ « Der Webanhalter
  16. Mar 19, 2009: How To Speed Up A Sluggish Wordpress Site | WP-Blogger

Post a Comment

Revolution Premium Themes