Since a lot of people out there land on my personal website looking for help and assistance making really really fast websites, which rank well in Google, often I’m asked questions about how to make fast sites.
I’ve updated this a little in 2021, since it was originally posted – including a variety of theme changes. It is worth recognising, I’m running WordPress at latest Alpha release, and the currently available “bundled” core theme, with no customizations – which is to say, I achieve speed you can achieve too, by following the thought processes outlined below.
If you’d like to make the fastest website in the World, how would you go about doing this?
Well, the short answer is, every single element needs to be 100% optimal.
I’ve been accused by some developers of practicing “micro-optimizations” which I take to be a compliment. Of course I practice this. Like a Formula 1 engineer, optimal is a case of piling micro-optimization after micro-optimization on top of each other in order to achieve a stack of optimized machinery which, when all is added together, is as fast as it is possible to go.
So where to start?
Let’s begin at the beginning. I’m going to talk about hosting a PHP web application, like WordPress. You can use JS frameworks, or write plain HTML which is very fast. But the majority of businesses use a CMS, and the majority of people who use a CMS use WordPress, because it is stable and easy for less technical members to familiarise with. So let’s speed up the typical WordPress stack.
This website – robinjescott.com – loaded during testing in 0.2-0.313 seconds on home. This post’s URL loads in 0.35-0.47 seconds (tested via Pingdom) in London, UK. Load times globally will differ a little, but all elements are fully loaded in under 1 second in all test locations.
Google PageSpeed score is 92. Yslow score is 100.
This website runs the latest version of WordPress, and a child theme of the stock Twenty Nineteen theme. In short, you can be this fast.
WordPress is Fast, Secure & Ranks
- Never been hacked – running WordPress.
- Under 0.4 seconds fully loaded – running WordPress.
- Ranked on the first page of Google results as “the fastest website in the World” – running WordPress.
Your Domain Nameservers and DNS
The nameservers you use to host your domain records, and the DNS records themselves matter in terms of speed.
There are two issues here: lag and server response time. There are other considerations here, too, such as TTL, which will tell all the various network caches around the world how long your domain DNS records are authoritative. Unless you are making regular changes to your DNS, and unless you have a particularly fast and globally available namesevers, you should set this to be pretty long, like 12 or 24 hours (or more).
My recommendation for your nameservers is to look at globally available service like AWS Route 53. These cost something like $0.50 a month to host all your domain’s DNS, but are blazing fast globally.
Set your domain @ records TTL to be 48 hours or longer if you don’t expect to change these – allow network level caching to do it’s thing.
Your Hosting Machine & Stack
There are a lot of elements to the hosting machine, but general rules apply, as well as some specifics.
For WordPress sites, I recommend either:
If your site is a PHP application running Magento or similar, I recommend to try your site on Cloudways – use Vultr.
Note if your site is WordPress with WooCommerce, have a look at the Best WooCommerce hosts here.
Don’t use Shared Hosting
If you are looking for optimal, do not use shared hosting. This is a recipe for disaster, because (and the clue is in the name) your site will share resources with others, leading to bottlenecks.
Use a VPS, Cloud Host or Dedicated Server
You want your resources dedicated to your instance. Which is best depends a little on the size, scaling requirement, and location of your hosting machine – all of which are debatable – and whether or not you need clustering or redundancy to be factored in.
Buy as much hardware as you can afford… but not more than you need
I often see people throwing hardware at sites in an effort to go faster. It doesn’t work like this. You need RAM and CPU to be sufficient, and there is a performance advantage to certain choices (like choosing SSD drives, or having more CPU cores for certain operations) but in a lot of cases, the hardware needs only to be sufficient. Big enough, and capable of holding the fastest software is sufficient here.
The Web Server – Nginx
Apache is slow. There, I’ve said it. It is also a very powerful and stable web server. In my opinion, Nginx should be taking the initial requests, however, and either serving directly, or caching apache’s slight slowness out of the mix.
As someone has commented, Litespeed is a reasonable alternative to Apache. I’ve found that a LEMP stack will marginally outperform Litespeed, and I have a slight preference not to use proprietary software (Nginx is Open Source). Certainly, taking Apache out of the equation is a Good Thing.
Use PHP 7.4+
The most recent version of PHP is faster than the last. It’s also more secure. But, you will likely need to refactor your code to be error free, particularly if you have code which is a few years old. Consider dropping support for older versions of PHP in your code, if you will never use them.
MySQL – Consider MariaDB 10+ or MySQL 8
MySQL 8.0 is looking likely to be a real performance boost. Until this is regularly available, MariaDB 10 is a really fast alternative. Please note that conversion from MySQL 5.7+ to MariaDB is not straightforward, so you need to make a decision at this point (there are other ways to import data, but it is worth remembering to make your decision at MySQL 5.6 with this in mind).
There are other (somewhat political) reasons to make the MySQL vs MariaDB choice. I’ll not get into politics here, except if it impacts speed. MySQL 8.0 shows a moderate performance boost over all equivalents in my most recent benchmarking.
Look at your Code
Maybe I should have led with this. Slow performance is almost always a result of some code (or lots of code) in the system which does things the long way around. You need all the elements of your code to do things fast. Think fast first when you are choosing everything software related, including your theme and plugins if you use WordPress.
Check Your Plugins
If you’re running a WordPress site, you’re likely using Plugins. Not all plugins are made equal. Some are quite slow. At the most basic, try to identify any plugins which are generally slow (load the site with / without them – I use WP CLI profile tool for this, but just manually can work, if this is how you need to work!), and see if you can lose them altogether, or replace with a lighter option.
Once you start to consider each plugin added adds weight to your pages, you’ll become a bit more discerning about what goes into your WP site. Welcome to my world! But also, this process is necessary. You’ll never be optimal if you only think about how things look, or the functionality you need, without considering the performance issues this feature or additional code will raise.
BUT, remember, there is a cost to everything, and sometimes, the cost is worth paying. I liken this to a fast car – want to make it even faster, take some weight out. Removing the back seats would make your car faster, but maybe you want seats! If you want seats in your car, removing them would be absurd (though faster). It isn’t as simple as “only thinking fast” for a car, and neither is it for a website. Optimal means the fastest car with back seats. Or maybe you need to transport 40+ people, in which case, you’re looking to make a bus travel faster. A different task, entirely 🙂
Check Your Theme
Again for WordPress, your theme could be the source of some slowness. In general “multipurpose” premium themes which are purchased and contain almost everything in an options panel are slower than custom built themes, which can be kept very light.
This is like comparing that good old family car to a tricked out racing 4WD rally car again. They have the same roots, and they look similar, but they are built for completely different purposes.
But you’re here looking for the fastest website in the world, right?!
If you want the fastest car in the world, you wouldn’t start with an SUV (a general purpose vehicle). You’d probably start with a sports car.
For the fastest website in the world, you’re probably going to need to get your virtual hands dirty coding a custom theme – or at least developing a light-weight starter theme.
Got WordPress? Get Speed
Couple of services you may be interested in if you are a business and you run WordPress to really speed away from your competition:
Got Questions – Leave them below
There’s obviously lots more I can add in here. If you’re interested to know more, see my long guide to optimizing WooCommerce for some granular stuff you could get into, or ask a question below.
I aim to build this section out more over time to become a working guide to the fastest possible stack for your PHP web applications.
Please ask and complain if you agree, disagree or want to know more.
How do I get a Fast Website?
- Choose a fast framework or software (WordPress is a good choice)
- Choose a fast host (see my post on best WooCommerce hosting – the recommendations in there are fast)
- Don’t add plugins or frameworks which are bloated or perform “slowly” (test them!)
- Optimize your images – and serve them in “next gen” formats, like Webp – so they are as small as possible
- Lazy load elements which are unseen without scrolling – someone who doesn’t scroll won’t need to load this stuff (this includes images, CSS, js and etc)
- Think mobile first – consider AMP (yeah, there’s some issues, but it is blazing fast)
- Cut out the cruft generally – optimization is a way of thinking, not just some magic bullet. Think about how to say what you need to say as fast as possible.