Free consultation

Based in Vancouver, Deepnet Media offers internet marketing and commercial web consultancy.

Optimize WordPress for Speed

Optimize WordPress for Speed

wordpress-logo

A fast website is probably one that loads in under 2 seconds by today’s standards, but it is amazing how many sites still take well over 8 seconds. It may not be possible to get all web sites under the magic 2 second mark, but even a slight improvement in speed can drive up conversion rates, increase the depth in which users explore your site and help to increase search traffic.

Google is now rightly factoring site speed into the rankings of websites and although at the minute a slow score as measured by Googlebot and an aggregate score from Google toolbar users is only said to be affecting 12% of websites – it is going to become a bigger ranking issue over time. Putting a side the end outcome of increasing rankings another SEO benefit of a fast loading site is that search engines are more likely to crawl deeper into your site, after all crawling billions of pages takes time so the engines do reward sites that can feed them pages quickly with deeper more frequent crawls.

The following are some quick easy fixes and some more involved tweaks in order to optimize a WordPress website for speed.

Upgrade to the latest version

It might seem obvious but many sites are still running a WordPress install that is 18 months out of date. Not only is this a security risk, but also the later versions of WordPress contain many optimizations for speed that were not in earlier versions.

[box type="info"]But remember backup everything before you upgrade – especially if you are upgrading from a really old version.[/box]

Upgrade those Plugins

In the same way you have upgraded the core CMS, it is worth keeping on top of all plugins as plugin authors are always learning new ways of making it run faster, be more compatible and importantly fixing those security holes.

Delete Plugins you don’t need

While you are looking at plugins, one of the easiest fixes is to remove any unwanted plugins that are currently activated in your WordPress install. Every plugin gets loaded and executed even if they are not in use.

Install W3 Total Cache

One of the best WordPress plugins for optimizing your site for speed is W3 Total Cache. Not only will this plugin allow you to cache whole pages, but it also gives you granular control over things like Gzipping the HTTP delivery of the pages, Minifying your HTML, CSS and JavaScript and even an easy way to integrate you theme files with a CDN (see Below)

Make sure you set W3 Total Cache to strip comments out of your code, after all they serve no purpose for anyone but you and your developer and while you are at it might as well combine all of your CSS and JavaScript into One at a per template level in order to avoid extra http requests to your server.

Remove unwanted PHP from templates

You may have bought an amazing theme from the likes of Woothemes.com, but when they made it they didn’t have you in mind and built it for any one to customize via a variety of backend menus. Once you have customized it to your site it is worth going into the templates and hard coding the choices that you have made. If you do this you can save many database calls on the following:

  • Site Name
  • Logo URL
  • Site Description
  • Navigation links
  • Links to Social Media Profiles
  • Variables that check if a featured box is to be show or not

Move that JavaScript

Move any inline Javascript to the footer of the site if it is unable to be loaded asynchronously, this allows the rest of the page to render in a users browser instead of it having to wait for the Javascript to be loaded and executed.

Optimize your WordPress Database

Over time the MySQL database that powers a WordPress site vane benefit from being optimized. You can either do this via phpMyAdmin or an easy way is to use the Optimize plugin from Yoast.

Remember to deactivate it after use to avoid it being loaded for no reason!

Move the Database to a separate server

On very high traffic sites it’s worth looking at moving the database to its own dedicated server and using Memcached to reduce the number of queries that actually reach the database. WordPress can utilize Memcached easily via the awesome W3 Total Cache plugin.

Turn Off Post revisions

Every time you fix a spelling mistake within a post you are causing you database to bloat as WordPress stores extra versions of your post to enable you to restore to an older version. This extra data takes up space in the database and probably isn’t required and cause a database slow down. Also WordPress itself gets sluggish when you approach the 10K post mark so having a whole load of redundant revisions is getting you there quicker.

To disable post revisions add on of the following to wp-config.php

define(‘WP_POST_REVISIONS’, false); // to disables post revisions completely

define(‘WP_POST_REVISIONS’,2); // to only keep last 2 revisions

Social Media Buttons & Badges

They are great for driving traffic and helping your users to share content, but do you really need all of them?
The most popular social media buttons display an interactive vote or like counter using a JavaScript call back to the social media mother ship. This is an additional http request and pause and can have a detrimental impact on speed when you have a lot of these buttons on a page. The best advice here is to look at where you traffic is coming from and where it has potential to come from. For example unless you are paying a network of power users don’t bother with a digg.com button it won’t bring you traffic but it will slow down each page load. The Facebook button also makes a request back to Facebook which is often slow, but chances are Facebook will deliver decent traffic so its worth keeping.

One thing to avoid is including social media Javascript on a per post level on list pages, as this can cause 10 calls to each social site for the single page load.

Embedding Videos

If using video embed codes from YouTube or Vimeo make sure you use their latest iframe embed code as this will not slow your site down but instead load in parallel. In WordPress you cannot just paste an iframe so instead you need to use a plugin in order to enable the use of tags for that player, but there are plugins to make it work.

Avoid the http traffic jam

The http spec implemented a suggestion that no browser session should hold more than 2 sockets to the same server and many web browsers keep true to this even today. One easy solution is to move all of your assets such as images, videos, CSS, JavaScript to a new sub domain such as static.yourdomain.com. This allows the browser to load files from the main site and the subdomain at the same time, effectively doubling the amount of files that can be loaded by the browser at once. If you have a site that contains a lot of assets on each page – for example a grid of thumbnail images – you can scale this to run over many subdomains such as static1, static2, static3, and static4 and then use PHP to randomize the host that is called per file.

If an image is required more than once per page, you will need to ensure that the randomization is intelligent enough to assign both instances of the file the same host. If you don’t the different host name will make the browser think that it is a different file and then reload the image rather than pulling it from the cache.

Use a Content Delivery Network

Content Delivery Networks take a copy of a set of your files, such as images or videos and cache them on many servers around the world. The idea here is that the files are then available on a server only a few hops away from any user requesting them. For example a user trying to stream a video that is hosted on a London server, who lives in Hawaii will greatly benefit from the video being cached in Honolulu. CDNs used to be only for the biggest websites as the big CDNs like Limelight and Akamai are financially out of reach of a small website. Recently new CDNs have emerged that are aimed at the smaller website, these include MaxCDN and Amazon Cloudfront.

WordPress can easily be set up to serve static files from a CDN without making any code changes to the theme, you simply need to use the W3 Total Cache Plugin which has a CDN configuration page.

Use Asynchronous Google Analytics

Google analytics is traditionally a piece of JavaScript that sits at the bottom of each html page and once loaded captures the information on who is on the website and what they are doing. The trouble is that the old Analytics code was synchronous meaning that it acted as a bottleneck for your browser and when it loaded the browser was unable to finish rendering the page until it was complete. Google have recognized this and released a new asynchronous JavaScript code that gets called from the head of the page. With the Asynchronous JavaScript the users browser is able to load it in the background while continuing on to the rest of the html, resulting in a slightly improved load time.

The simplest way to utilize this on WordPress is via this Google Analytics WordPress plugin, which also has some great customization options.

Fast Web hosting

Hosting your site on an overcrowded web server at a cheap web host is going to kill all of the speed optimization work you have done so far. It really is not worth saving a few dollars to end up with a website that’s takes 10 seconds to load and crashes at the first sign of popularity. A good web host will not only have made the investment in expensive infrastructure, but they will also be monitoring load and adding new resources to meet demand.

There is a hosting company who specialize in hosting WordPress sites, they are incredibly fast and have invested millions in infrastructure and bespoke development in order to host and deliver the fasted hosting that you could want for a WordPress website. The company is called WPEngine and they have received investment from the owners of WordPress (Automattic), so they must be doing something right. Check out WPEngine and try their evaluation tool that can assess your current site and let you know how much they can speed it up.

Find out what else is slowing you down

Once you have completed these steps you should also test your site using the Yahoo! Yslow browser plugin or Google’s Page speed tool. Both of these tools will highlight any other issues with un-optimized CSS, too many http requests or other issues that you may not have considered.

Mark Tempest

Mark Tempest has spent over a decade planning, developing and promoting consumer websites and online products.