The Ultimate Guide To A Super Fast WordPress Website or Blog
WordPress has developed a reputation for it’s lethargic state especially when confronted with large volumes of traffic, but it needn’t be that way if properly configured, even in shared hosting environments. If you’re experiencing a slow WordPress website or blog we’ll look at how you can dramatically improve performance without dramatically shifting your budget. Some of the bottlenecks we aim to address may include things that you may have not even considered before. We’ll talk about everything from hardware to web servers to CDNs as well as internal optimisations you can make to WordPress. It’s also worth noting that people expect one change to completely boost the performance of their site, however bare in mind a collection of marginal gains can go a long way. So it’s worth exploring all the options we discuss here which in isolation may only produce small results but collectively should amount to a supercharged WordPress website or blog. So without further ado let’s get the ball rolling.
If your WordPress website or blog is experiencing performance issues then the best place to start in correcting them is by testing load times with a variety of tools. Not only will this help you gauge what potential bottlenecks may exist but it will also give you an idea of any improvements that may be made as you go through the optimisation process giving you a clear idea of the impact of your various changes.
There are several services that allow you to test the load speed of your website. We like pingdom . It will give a series of suggestions once it runs the test using google pagespeed, however if you’re not so technical you may not know how to interpret the results or understand the recommendations. With that said at the very minimum you can see your load times and compare them as we go through this journey. You can also try GT Metrix.
P3 Plugin Profiler
P3 Performance Profiler is a WordPress plugin developed by GoDaddy in order to help users identify the impact of plugins and themes on the speed of their website or blog. If you are having performance issues P3 may be a good first step in identifying what plugins may be having a negative impact on load times. Every plugin will have some sort of impact on performance even if minimal but you’ll be looking for any that seem to be more drastic than the others.
Now that the testing is out of the way and we have an idea of where we stand it’s time we start with the very foundation of your WordPress website or blog; the hard drive that stores and serves your content. Traditional spinning drives tend to be a lot slower due to moving parts and depending on the task being performed Solid State Drives (SSDs) can be up to 10 times faster. This is particularly important because WordPress is database driven and large sites with vast amounts of content will have huge databases that need to be read. The quicker it can be read and queried the quicker your website will run. Not only that but other static content such as image files, css files or cached html files will also need to be read from the drive and will benefit from faster SSDs. Most modern web hosts such as ourselves now use SSDs exclusively, however there are still those that don’t so it’s always good to double check especially with budget web hosting solutions.
MariaDB and the Database
We mentioned databases being how WordPress stores your posts (and even your settings), and how important it is to be able to read and write to the database as quickly as possible. For this reason you should probably find a web host that uses MariaDB rather than MySQL. MariaDB consistently out performs MySQL in benchmark tests.
In addition to your choice of database engine it is also worth periodically optimising the database. Over time databases can get bloated through normal use. Optimising the database will remove any cruft and the resulting smaller database size should result in faster reads. You can use a plugin such as WP-Optimize for this process, however it is not compatible with the innodb storage engine so will not work on the database tables. If you find that you’re using innodb then you’ll need to optimise the database using phpmyadmin. With that said Wp-Optimize doesn’t just help with optimising database tables it is also nifty at removing unnecessary data such as old post revisions unapproved/spam comments and much more. You can use this guide on optimising your wordpress database for a comprehensive break down on a streamlined, leaner database. It is always advisable that when doing anything with your database you first take a backup as changes are irreversible.
One of the ways you can keep your database lean is by limiting post revisions proactively as WordPress will save an infinite amount of revisions if you’re saving often enough. I’ve found 3 revisions to be a solid hard limit . You can do this by adding the following to your wp-config.php file:
you can change ‘3’ to any number that works for you
In an extreme case you may even decide that you don’t want revisions on at all. Although not recommended for the most part you could do so by adding the following line to your wp-config.php:
define('WP_POST_REVISIONS', false );
Litespeed Web Server
As you can see, so far we’ve established a solid foundation of fast hard drives and solid database performance. The next layer in this backbone is the web server. We recommend finding a web host such as ourselves that utilises Litespeed web server. This is for several reasons. Firstly we believe Litespeed to have the fastest and most stable php handler on the market, Litespeed API (lsapi). Granted segments of lsapi have been open sourced and hosts utilising Cloudlinux on apache can benefit from it but it still doesn’t come close to the real deal. This is significant when processing the code of plugins, themes and core WordPress. Secondly Litespeed is simply the fastest way to serve static content such as images and html files period.
You may notice that we mention Cloudflare quite a few times in this guide and with just cause. Once upon a time content delivery networks (CDNs) were reserved for the biggest websites with the biggest budgets. Cloudflare changed that completely with their free CDN service. A global CDN such as CloudFlare is important as it can reduce the issue of latency. If your website is visited by somebody from America but your website is hosted on a server in the UK then essentially the data will have further to travel hence appearing to be slower than if someone closer was visiting. Cloudflare saves your static content and serves them to your visitors from datacenters in their vicinity and thus reducing the problem of latency.
Remember Cloudflare can only cache static content which means Cloudflare alone can’t save you if you haven’t taken other steps such as page caching but in conjunction with removing other bottlenecks it works wonders. It is also worth noting that it doesn’t cache html files by default although this can be done using page rules.
The second major advantage of CloudFlare is railgun. Railgun works on a server level by essentially tracking the binary changes of web page requests, subsequently improving the performance of dynamic or uncached content. To benefit from Railgun you need to be hosted with a Cloudflare Optimized Partner.
This is perhaps the most important step to optimising the performance of any WordPress website or blog. Every time someone visits your website the server needs to execute the php code and query the database in order to serve the web page. Good web hosts will have means of caching database queries and PHP code, however this isn’t enough.
The key is to stop requests from even needing to touch PHP or the database when serving a web page. This is where page caching comes in. Essentially page caching works by saving the html output generated by WordPress via PHP and the database and storing it as a single file for a set period of time. If a cached file doesn’t exist when somebody visits a page then WordPress will process this request as normal generating the html to be cached in the process. Any subsequent visitors will then be served with this cache file until it expires or is purged from the cache at which point it will need to be regenerated.
If you’re on a host that utilises Litespeed web server you can take advantage of the best cache on the market today, Litespeed Cache for WordPress. If you’re not on a host that utilises Litespeed then we tend to recommend the use of WP Supercache. This is generally because it is a lot simpler to use out the box for most beginners who may get confused by the multitude of configuration options offered by W3 Total Cache. If you’re not on a Litespeed and you don’t mind paying for a commercial solution then WP Rocket may be the way to go.
Browser caching plays an often under appreciated role in the speed of your WordPress website or blog. The idea behind this is that you instruct the browsers of your visitors to save resources from your website for a set period of time. By doing this the browser shouldn’t need to redownload a particular static file from your site and instead just use the version they’ve already saved in the local cache. So as an arbitrary example, on a 3mb page your visitor may only need to download 1mb if they have visited your site or particular page before.
Browser caching is encouraged using request headers. W3 Total cache has a settings page dedicated to this but the options can be placed in your .htaccess file using the following snippet taken from WTC:
If you’re using Cloudflare you can also take advantage of browser caching by changing the browser cache expiration settings to 1 month.
Browser caching is great but you must note the major caveat. If somebody visiting your site has a file cached, their browser will always serve the local version meaning if you change a file but keep the same URL then your visitors may still see the old cached version. This can be overcome by updating file names when they’re changed or setting shorter expiration times, although the latter would somewhat defeat the purpose.
If you’re using Cloudflare and notice you’re still being served a cached version of a file despite your browser cache being cleared it could be that you also need to clear the file from Cloudflare (note you shouldn’t purge the entire cache just the specific file).
Something that often goes hand with caching is Gzip compression. It allows your visitors to download smaller files however the process of creating smaller files requires processing power so there may be a performance knock in under powered environments. To enable Gzip simply add the following lines of code to your .htaccess file:
If you’re using Cloudflare it will automatically Gzip your static resources so enabling it on your host shouldn’t be necessary.
PHP is traditionally quite slow especially when compared to other programming languages. The extent of this is illustrated by the fact that Facebook, originally written in php, abstracted it to create their own version known as HipHop Virtual Machine (HHVM). PHP 7 changes this dramatically and in benchmark tests is twice as fast as the previous PHP 5.6 and can even out performs HHVM under certain conditions and comes a very close second under others.
If PHP 7 is not on by default then you can activate it using the PHP selector of supported web hosts such as ourselves.
Traditionally HTTPS sites were considered slower than their HTTP counterparts. This was largely due to the time it takes to establish a secure connection as well as encrypt and decrypt the data. So how will going HTTPs make your website faster you ask? Simple, HTTP/2! HTTP/2 is the latest iteration of the HTTP protocol and boy it’s fast. However, to take full advantage of the speed increases it requires an HTTPS connection and a supporting web server. Both Litespeed and Cloudflare support HTTP/2 off the bat so if you’ve followed the above guides you’re in good stead to benefit from the performance boost of this new protocol.
Securing your site needn’t cost you a penny either. You can now get free SSL certificates from entities such as Start SSL or Letsencrypt. Cloudflare also provide free certificates with their universal SSL. If you’re using Cloudflare, then we still recommend installing a valid certificate on your website or blog. Having a valid SSL certificate will allow you to turn on strict SSL at Cloudflare which we recommend as it forces Cloudflare to ensure it is securely connected to your server.
Optimise Your Images
The web is becoming more and more image heavy especially with the new full bleed (edge to edge) convention. This also for the most part means people are uploading larger images but how many of you are taking the time to optimise them before hand.
Optimised images come in 3 flavours. Firstly, dimensions. You needn’t upload an image thats larger than the width of your content area. Most content areas in modern design frameworks with sidebars tend to be 720px wide so in theory that should be the maximum width of the images you upload because they would never fill a larger space. Granted if you have a full bleed design you may require images as large as 1920px wide which is fine, but the emphasis here is that your images shouldn’t be wider than necessary.
The second flavour of image optimisation comes in the form of compression. Lossy and lossless compression techniques will maintain the perceived quality of the images whilst decreasing the overall file size.
The final flavour of optimisation comes in the form of stripping unecessary data from your images. Images come with extra baggage known as metadata. Metadata consists of information such as the time the image was taken all the way through to location data. Removing metadata from your images will result in smaller file sizes. You can read more on how to achieve the optimisations in this how to optimise your images post.
As the web becomes more and more visual so too is there an increase in the amount of images and other frames being loaded on a page. If you have image heavy blog posts or alike then it may be worth lazy loading. Lazy loading works by only loading a resource when it becomes visible to the user. The result is perceptively faster load times. Of course your images will still be loaded eventually even if lazily so it’s still important to ensure they are optimised for faster load times. We recommend using BJ Lazy Load for this task.
Only Install Plugins You Absolutely Need
Do you have more than 10 plugins? If so why? If you can’t absolutely justify the need for each plugin then uninstall them especially if your tests with P3 identified them as a significant bottleneck. As previously stated your server needs to execute the code and the more code to process the longer it will take.
It is also worth mentioning that not everything needs a plugin. Sometimes a few lines of code can achieve the same goal as a more comprehensive plugin. We generally recommend installing Code Snippets for this reason.
Another thing to note is that plugins will slow down your sites in different ways one of which is running expensive queries on the database. Related posts plugins tend to be a common culprit of this. For this reason we recommend using Jet Pack for your related posts as it will process these queries off site.
Cut Down On Unnecessary Cruft
The compulsion for new website or blog owners is to overload them with everything ever. Widgets of all shapes and sizes pulling in images and all sorts from many sources. Is it all really necessary? Did you realise that Twitter widget you’re using was also pulling in an extra 2mb of images? What about those 5 display ad slots you added?
Ask yourself what your motive is for any additional content and decide on its necessity. It could be that you want to show off your tweets and a simpler twitter widget may suffice. Essentially by asking yourself the right questions you may find simpler solutions or even realise that a particular widget isn’t actually necessary in the first place. Ads and other tools pulling in content from 3rd parties will invariably slow down your WordPress website or blog so implement them wisely.
Use A Fast Theme
Another key to a fast theme is to not show the entire content of your posts on your home or archive pages. Simply show excerpts that encourage people to read more. This is especially important if you have an image heavy blog. Imagine loading the content of 10 posts each of which with 5 large images of course lazy loading could help in this instant but just avoid it full stop. Not only will the large size of the page slow your site down but also the amount of requests it will take to load the page.
A Few Left Field Tips
If we hadn’t already covered enough here are a few bonus tips:
Disable Flash and Interactive Ads
If you’re serving ads using Adsense or a similar ad network then it is highly recommended that you disable flash and interactive ads. Firstly they’re larger than most other ads and secondly flash ads pose a security risk to your users with the recent rise of malvatising.
Pick a host based where the bulk of your users are located as this will reduce latency for them. We mentioned that a global CDN such as Cloudflare will eliminate latency to some degree, however it isn’t serving your whole site from its cache and thus requests that come from your server will still benefit from being closer to your users.
Infinite scroll is a form of ajax isn’t for everyone depending on the design of your website or blog but it can however speed up parts of your website in the following way. Let’s say that when someone visits a page on your website containing 10 paginated blog posts (i.e. your home page or archives). Once they reach the bottom rather than reload a whole new page by going to page 2, page 2 is loaded. This is quicker as only.
However depending on the configuration, content loaded by infinite scroll won’t always benefit from caching and the database will still need to be queried in order to pull in the appropriate posts.
So there it is, everything you need to know to speed up your WordPress website or blog. If you made it this far then perhaps you should give yourself a pat on the back and make yourself a well deserved cup of tea. Hopefully by now you’re feeling like Speedy Gonzalez and your website is whizzing away.
If you’ve tried any of the steps we’ve outlined then let us know how they worked for you in the comments below.
Until next time.