How to Optimise WordPress for Speed and Performance

As most people already realise, WordPress is a great platform to use for your website. Unfortunately, it suffers from a common side effect of becoming sluggishly slow if it is not maintained correctly as the amount of content in the site grows. This can be a real hassle for visitors to your website, resulting in fewer potential subscribers or customers as a direct result.

Nobody wants to deal with a slow website, and they may leave for one of your competitors before it even has had a chance to finish loading.

There are many different ways that you can optimise a WordPress website, some of which will work wonders and some that only add a few milliseconds second or so. Large websites will want to take advantage of every single method whenever possible, but smaller websites will probably suffice with a couple of updates.

Plugins

In many ways, plugins are both the best and worst thing to be a part of WordPress; while they can offer convenience and functionality to a website, they are notorious for breaking its performance as well. The first thing to do when optimising any website is to see which plugins are not worth the trouble. Naturally, it is somewhat challenging if you house a high number of plugins at a time.

There are other plugins that can help identify which plugins may be doing more harm than good, such as the P3 Profiler; this plugin examines its counterparts and determines which one has a high impact on performance compared to what it offers the website.

For example, if you run a website with frequently added content, you’ll eventually run into an issue with “popular posts” and “relevant posts” taking too long to scour the entire site.

A good general rule of thumb to consider is that you should never use a plugin when code will suffice.

#Install a Cache Plugin

If you have pages on your website that are frequently visited more than others, it is essential to get a cache plugin to cache the page, allowing its immediate image to be displayed to the visitor. This plugin generates files using HTML without ever having to run a line of PHP for each user.

cache-plugin

Those looking for a plugin to guide throughout the process, WP Super Cache is a good plugin for novices. Those with some more experience may want to give W3 Total Cache a try. If you run a site on shared hosts you may also want to try out Hyper Cache, a lightweight option that works for an average blog and helps increase its speed without demanding too much of you.

# Delete Inactive Plugins

Because there are tens of thousands of different plugins out there, it’s hard to resist trying a new one out, even if it’s something we don’t really need. Many website owners are guilty of trying a new plugin and deactivating it when it is no longer useful, but not actually uninstalling it from the server. While it might not directly hinder the performance of a website, it clutters the user from the real work and takes up space that would be best used elsewhere.

Choose the Right Hosting

The next step to optimising a WordPress website is to ensure that your own hosting is not the one responsible for the slowdown.

#Web Hosts

There are some sites that simply run too slow for larger websites, especially with hosts that put thousands of different blogs onto a single server to share, causing terrible slowness.

Choosing the right company to host your content is absolutely important. While this does not mean having to break the bank on a dedicated server, it does mean it will require some homework to get a dependable company that will work with the budget you have laid out for it.

It can also help to get a managed WordPress host in order to have support for your blog.

# Update your WordPress Version

Whenever WordPress has a major improvement to its platform, a new version is released. Ensure that you always keep your copy of WordPress up to date with the most recent and stable installation to ensure that there you have the safest and fastest copy of WordPress available to you.

# Manage the Database

Databases over time can become fragmented and need repairing. You can easily optimise and repair your tables in PHPMyadmin if you are using a cPanel host.

It is important to ensure this cache is enabled and working optimally for your website, which means MySQL does as little work as it can, allowing other parts of the website to use the resources.

A tool like mysqltuner can help ensure that the performance of your tables is as good as it can be. For those with a website that is largely text-based and has a high level of traffic may prefer to use InnoDB or a similar engine. The switch will not impact the quality of search. Other distributions of MySQL like Percona can also be useful with WordPress.

# Optimise your Images

As most could already figure, images are one of the biggest parts of a website, so it is important to optimise these as well.

First, make sure that you specify the biggest possible dimensions for large-, medium- and thumbnail-sized images. This means uploading an image that is 1920px wide in a content area that only accepts 604px, the CSS will scale down the image to the appropriate size. However, if you were to specify the size, then it will only display the resized image, which is much smaller than the original.

You’ll also want to reduce the size of your images without completely resizing them or without the worry of sacrificing the quality. There are some plugins that will allow you to reduce the size of images losslessly. For example, Smush.it by Yahoo uses a number of optimisation techniques for image formatting to remove bytes that are unnecessary from the image, meaning the image quality is not sacrificed. There is also a plugin for frequent use.

#PHP vs HTML

PHP is comparatively slow compared like HTML, which processes much faster on a web server; in fact, it can process HTML about 20 times quicker than PHP. For those who have a good amount of preliminary knowledge with both HTML and PHP, there are some instances where you can replace the PHP of your website with HTML.

It is better to replace something that you typically do not change, such as the name of your site, the URL to your theme’s stylesheet or the URL to your site favicon. An easy hack  is to view the source of your page, copying a portion of the HTML that was generated and swapping the PHP command with it.

#CSS and JavaScript

Out of the box, many WordPress themes generate a lot of JavaScript files and CSS files, and every single plugin that you install may add to the total number of these files. In fact, it is very common to see a single website housing six or more JavaScript files and over 10 different CSS files.

Fortunately, there is a way to optimise this as well: by combining the two kinds of files whenever possible. Specifically, there are plugins like Combine JS and Combine CSS. Each of these plugins, as the names suggest, combine the two different kinds of files with their own type so that your website only has one CSS file for all plugins and one JavaScript file for every function.

In some cases, this can break the functionality of a plugin, so there may be a couple of instances in which you may need to exempt a plugin from being combined, but even going from 12 CSS files to two or three is a major improvement. There are also some plugins that might not work well with other plugins, but running the P3 Profiler plugin may have already shown you that it was a problem plugin in the first place.

Another way to help enhance the performance of your website is to move all of your scripts to function within the footer. This would typically require the ability to dig into your theme and use programming skills to complete, but now there is an easier solution in the form of the Scripts to Footer plugin. Again, there could be issues with conflicting plugins, so you will need to test each one.

You should also minify CSS and JS as much as possible by removing whitespace within the files.

#Flushing the Buffer

It takes up to half a second for a website to come up with the HTML version of the website, during which time the browser is completely idle. Using the PHP function known as flush() can help assist with this by loading a partially loaded page to the web browser so that it may start getting the components as the server continues working on loading the remainder.

In order to do this, you can open up the header file for your theme and locate the ending head tag, inserting the appropriate function within your content. If done properly, you will have a file that looks like the following:

</head>
<?php flush(); ?>
<body>

#Revision History

Optimisation of WordPress would not be complete without some changes on the admin side.

Every time you write a new post in WordPress, the platform will save the revision history, even if the post has long been published on the website for some time. When you have posts that are even a couple of weeks old, there is no reason to hang on to the tens of revisions that still remain.

There is a Revision Control plugin that lets the user remove any revisions from old posts, which helps decrease the size of your WordPress database and makes your website run just a little bit faster in return.

# Automatically Empty the Trash

You can set WordPress to automatically empty the trash. Simply add this line to your wp-config.php file. The number basically refers to how many days between WordPress trash dumps in this example it is set to 10.

define('EMPTY_TRASH_DAYS', 10 );

# Utilise a Content Delivery Network

This is another means of caching offered as a benefit for publishers. The idea here for performance is that there is low latency access to media if the owner chooses to host with them. With a content delivery network, you can host your site anywhere you wish; if you have a visitor in another part of the world, the CDN will cache what is nearby and shave away seconds off the load time for your website.

Of course, it can be tricky to cache and purge old content since, in an optimal setting, users are always getting the latest images, latest CSS and the latest Javascript versions. Ensure that you can automate this prior to taking this step; just about all publishers will notice a reduction in page load time using a content delivery network and image optimisation.

# Disable Hotlinking

Hotlinking is a term that refers to another person using an inline link in order to display images that are still hosted on your server. That’s right, the ones who find your image through Google Images and not only assume that you do not mind the image being used but accept that it is okay to embed it on their own website while hosting it on yours, taking away your bandwidth.

The way to stop this is through your .htaccess file; remember to back up the existing file before making any kind of changes to it. Add the following into the file to disable

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourdomain.com/.*$ [NC]
RewriteRule .(gif|jpe?g|png)$ - [F]

#Akisment and Spam

Comments take up plenty of room inside of your database, so there is yet another reason to get rid of all those spam comments on your blog. With every copy of WordPress comes the Akisment plugin, so take advantage of it and set it up so that these comments can be caught and stopped before they go into the database and show up on your website. This should stop spammers from going to your website in the future as well.

It is quite simple to set up Akismet. The only thing you must do is go to the Akismet website and register for an account with WordPress.com to obtain an API key. From there, you can enter the key into your admin panel and check off the box that allows the plugin to automatically delete spam that has been posted to posts over a month old.

At any time, you are free to look at the spam comments and manually empty the queue yourself.

#Disable Pingbacks and Trackbacks

It can be nice to see how often someone has linked to your website, but the truth is that pingbacks and trackbacks are not good for the performance of your website. Every time this happens, a new trackback is made and uses the resources of your database and server. Fortunately, it is very easy to disable this; you can find the setting within the Discussion settings of the admin panel.

#Other Settings

Adjusting other settings in the admin panel can help; for example, you may not really need to display 25 posts on your front page when five will suffice. In addition, you can also set the post to only show a certain number of characters within the Reading panel of your settings.

There are several other methods that you can take in order to optimise WordPress for speed and performance.

#External Video Hosting

Unless you have a very fast server with tons of space, it helps to host your videos on a video content site like Vimeo or YouTube.

#Eliminating Inner Communication

Look for any kinds of add-ons that use JavaScript or either plugins or widgets that are used for social purposes. If they are bringing you plenty of traffic, then keep them, or else dispose of them; more often than not, you’ll want to avoid the plugins that call back to another website. Use basic techniques for thumbnails rather than using huge images, and ensure you are using caching plugins.

#Smart Theme

It always helps to have a responsive theme so that it uses less resources for a mobile user. In this way, mobile users do not see huge images while desktop users do not need to see tiny images. It’s easy to specify what users should have which content based on the width of the screen.

#External Widgets

Widgets are another part of your WordPress installation that greatly affect the performance of the site. Optimise these so that they are very lightweight and can easily be loaded onto the site. For instance, a widget for Twitter, Facebook or a similar social networking website will require JavaScript and CSS from another website, slowing down the process.

If it is unlikely these two are going to be updated regularly, you can host them yourself; not needing to grab resources from an external server will help you increase the speed of your pages.

Do you want to work with

Purple Imp on your next project?