Is speeding up a WordPress site a problem for you? In this article I am going to give you detailed instructions to locate and solve the most common causes of slowness for a website.
(This post contains affiliate links. This means I get a commission if you make a purchase through my links. There is no additional cost to you, but it enables me to provide you information like this for free. Please read my disclosure for more info.)
1. Optimizing Your Hosting
1A. Server Resources
WordPress optimization itself is useless if your choice of hosting is poor. In order make the right choice, you need to understand the different types of hosting.
These hosts include companies like Bluehost, HostGator, Siteground or GoDaddy.
They offer “unlimited domains, storage and bandwidth” plans, 99.99 percent uptime.
The trick is that they never mention CPU and RAM and you are simply unable to compare these host based on those resources.
Unfortunately in the real world there is no such thing as unlimited resources. Therefore they limit and suspend clients that use a lot of CPU and RAM. The result is 503 Server Errors, website down and customer service tells you that you need to upgrade to a more expensive plan.
The average price is between $3 and $25 a month. The reality is, $3 a month doesn’t generate any revenue for the hosting company, especially when you consider the cost of support personnel and system admins.
They make money by
- placing thousands of people on a server where RAM and CPU are over-stretched,
- hidden fees and upsells – migrations, selling premium and expired domains, SSL certificates, etc.,
- offering huge signup discounts and charging a huge bill on renewal.
In the end, you have hosting companies keeping customers that either purchase upsells or don’t use a lot of resources. (Statistically 91 percent of web pages get zero traffic.)
The (angry) clients with successful websites either pay for the upgrade or leave, making room for more clients that don’t use a lot of resources.
As an example, let’s take a look at what Bluehost says in its usage policy:
“For packages supporting unmetered disk space or data transfer (bandwidth), we do not have defined limitations. These resources are “unmetered”, meaning you are not billed according to the amount of disk space or bandwidth used. While of course these resources are not infinite, we believe our customers should have all the resources necessary to build an online presence and 99.95% of customers will have more than enough disk space and bandwidth to meet their needs.
“That said, we do require all customers to be fully compliant with our Terms of Service and utilize disk space and bandwidth in a manner consistent with the normal operation of a website. While rare, we occasionally constrain accounts utilizing more resources than should be the case in the normal operation of a personal or small business website.”
The takeaway: Cheapo shared hosting may work at the beginning stage of your business. However as your business (traffic) grows, it is inevitable that you will need a different solution, otherwise your server will kill your site (and profits).
Option 2 – VPS
Running a VPS requires extra knowledge, but it is not very complicated to learn.
It is a bit of a DIY hosting.
I have the following configuration:
- CentOS 7
- NGINX>Apache>Varnish cache
- a domain for my server (SaadHost.com)
- CentOS Web Panel as my control panel. Premium only costs $11 per year (much cheaper than cPanel) and I can move it to a different IP if I need to switch servers.
In reality the biggest task in using a VPS is setting it up. Once that done, it doesn’t require a lot. It takes a few clicks to handle upgrades. If you have a problem, CWP offers one-time support for $7.49, monthly support for $12.99.
– Managed VPS
If you are brand new to this, you can learn by purchasing a Managed Digital Ocean VPS with a provider like Temok.
They will give you 1GB RAM/1CPU for $6 per month. That amount is insufficient to run a production site, because the server itself requires resources, but you can learn operating a VPS by placing a non-vital site on it.
Tip: Since I use GMail to handle my domain email, I turned off my email server’s Spam Assassin, AMAVIS and Clam AV, which waste tons of resources.
– Unmanaged VPS
Once I was familiar, I switched to an unmanaged SSD Nodes VPS.
On the 3-year plan 8GB RAM/2 CPU cost $150 for 3 years, cheaper than shared hosting.
(Compare that to Digital Ocean’s 4 GB/2 vCPUs unmanaged VPS at $20/month.)
They were nice enough to set everything up for me because I committed for 3 years.
Tip: You can share the costs if 3-4 people share the VPS.
Option 3 – Managed WordPress Hosting
These types of hosts are typically fine-tuned to work with WordPress. You get the best service for a high traffic site, everything is done for you and you get the resources that you need.
It is not cheap, plans for managed WordPress hosting typically range anywhere from $25 to $150 a month.
Popular managed WordPress hosts include Kinsta, WP Engine, WPX Hosting, Flywheel.
Kinsta’s entire infrastructure is built on Google Cloud Platform and is therefore different from the traditional shared, VPS, or dedicated infrastructure.
Every WordPress site on their platform runs in an isolated software container that contains all of the software resources required to run the site (Linux, NGINX, PHP, MySQL). This means that the software that runs each site is completely private and is not shared even between your own sites.
1B. Server Location
In optimizing site speed, the first thing to determine is where the majority of your visitors are coming from. This is important because your server location plays a significant factor in determining your overall network latency (delay in transmission of data over a network) and TTFB (how long the browser has to wait before receiving its first byte of data).
You want your network latency and TTFB to be as low as possible. One way to accomplish this is to choose a server closest to your visitors. The other way is to use a CDN.
1C. DNS Hosting
DNS is one of the most important components of network architecture and the backbone of modern network communications. If it wasn’t for DNS, we’d have to memorize all the IP addresses of the websites we want to use by heart!
By using a high-quality DNS hosting provider you’ll be more protected from potential DDoS (aka ‘distributed denial-of-service’ attacks).
At this point I don’t have much insight to share with you other than the following:
DNS speed influences your TTFB.
You can check DNSPerf to see the fastest DNS providers and if you click on Tools>DNS Speed Benchmark, you can check how fast your DNS is.
1D. Use Modern Hosting Technologies
It’s important to use recent technologies, for example
- SSD storage
- MariaDB 10.4 for the database
Use NGINX + Apache
Every WordPress host uses a web server to power your WordPress sites. The most common choices are NGINX and Apache.
The reasons for these servers’ popularity are clear: Apache’s power and NGINX’s speed are well known. However, both servers do have drawbacks — Apache is hard on server memory, while NGINX (great at static files) needs the help of php-fpm or similar modules for dynamic content.
Nginx reverse proxy for Apache is a setup that uses NGINX as front end, and Apache as backend. NGINX handles the incoming request from the browser and passes the PHP requests to the Apache backend.
HTTP/2 will make our applications faster, simpler, and more robust. It was released in 2015 and designed to speed up how websites are delivered.
Because of browser support, it requires HTTPS (SSL).
HTTP/2 does not modify the application format of HTTP in any way. All the core concepts remain in place. Instead, HTTP/2 modifies how the data is formatted (framed) and transported between the client and server. As a result, all existing applications can be delivered without modification.
Take advantage of the HTTP/2 protocol to minimize the number of communication round trips, thanks to parallelization.
Here is an HTTP/2 verification tool to check if your site is being delivered through HTTP/2.
If your WordPress host doesn’t support HTTP/2 you should start looking for a new provider. With the move of the entire web to HTTPS, this is no longer just a nice feature to have; it’s a necessity.
And I can tell you that on my VPS all it took was adding one single word to the NGINX config file.
Enable Gzip Compression
GZIP is a file format and a software application used for file compression and decompression.
Use PHP 7.3 or 7.4
If you compare PHP 7.3 to PHP 5.6, it can handle 3x as many requests per second.
PHP 7.3 is also on average 9% faster than PHP 7.2. This will impact your WordPress site’s responsiveness.
Unfortunately PHP suEXEC (CGI) technology doesn’t allow satisfactory results.
Using reliable and updated hosting technology can give you performance that’s 10-times better than what you’ll get with cheap, shared hosting.
PHP Memory Limit
In addition to having enough RAM on your hosting plan, you should also allocate enough memory to PHP as well.
This is set in your php.ini file and is usually editable in your control panel under PHP Configuration Editor.
WordPress memory Limit
By default, WordPress grants 40M of RAM memory for each process.
If your site runs some advanced plugins, you can hit the limit really fast. Therefore it will be necessary to increase the memory.
To do this, you can add this line in your wp-config.php file :
define( ‘WP_MEMORY_LIMIT’, ‘128M’ );
2. Avoid Resource Intensive Plugins
You have probably heard the statement that plugins slow down your site. This is not necessarily true.
Matthew Woodward’s blog has 56 active plugins.
Resource-intensive plugins do.
It is important to identify plugins that do this. In fact WP Engine maintains a list of plugins that are banned on their platform.
Here is for example the effect of the Broken Link Checker plugin on Siteground’s (expensive) GoGeek plan (at 600 visitors per day):
If you do a search, you will find statements like this:
“Broken Link Checker is designed to run in the background checking for broken links every so often, which basically means it slows down your blog, hugely impacting both your Reader’s experience and search engine rankings (fast sites rank better!)”
Compare the resources after switching this plugin off:
Look at the 3X spike in CPU executions:
Switching the plugin off saved around $500 by eliminating the need to switch to a more expensive plan.
Identify Resource Intensive Plugins
The first clue was the server stats – we are talking about current month executions on 9 Feb:
Why would index.php get executed 232k times in 9 days when there are only 18k visitors per month?
Contacting the web host helpfully identified the problem.
The other way to identify the cause of the slows is reading the Waterfall diagram. Take a look at this one:
The long purple line shows a massive delay.
WooCommerce Cart Fragments
The URL is the following:
If you Google it, you will find multiple people complaining about this.
… in order to update the Cart items and Cart total asynchronously i.e. without the need of refreshing the website page you’re visiting. Ajax is awesome and all, however don’t underestimate the performance implications and plugin conflicts this little functionality might cause.
The problem is, this gets done even when the cart is empty, regardless whether someone is on the homepage, shop page or a blog post.
Some more Googling and the Disable Cart Fragments plugin takes out this massive delay.
The Effect of Plugins On Your Database
One big problem with WordPress plugins is that when you delete a plugin, it usually leaves tables and rows in your database. Over time this can add up to a lot of data and slow your site down.
As an example, I recently moved a WordPress site and out of 130 tables, 50 percent were left over by deleted plugins!
WP-Options Table Bloat
When troubleshooting a slow WordPress site, the wp_options database table is often overlooked. This table contains a variety of crucial site data, including:
- site settings
- widget data
Almost every single WordPress page, from front end to admin, executes this query:
SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'.
If this query does not run efficiently, it will destroy a site’s speed.
Not all WordPress database tables suffer as they grow.
The wp_posts table, for instance, can be many times larger than the wp_options table without seriously impacting site performance thanks to an indexing strategy designed to handle very large datasets. Without this index, every page in the book would need to be flipped through to locate a specific term, every time.
The wp_options table is not intended to hold thousands of records. And yet, this table can become bloated quite quickly because:
- plugins often store data in wp_options rather than in other tables
- A bug in plugins
I discovered this problem accidentally – I looked into the table and it had around 4,500 rows.
There were remains of at least 20 long-removed plugins and tons of transients.
After cleaning it up, the size went down to about 800 rows and the site speed decreased from 3.8s to 1.8s.
Admin-ajax and Heartbeat API
WordPress heartbeat is an API service that sends a continuous pulse to perform periodic tasks. This helps the server provide real-time information on the WordPress dashboard, such as locking information of a post by another author.
It is a not widely known fact that the WordPress Heartbeat API uses admin-ajax.php to run calls from the web-browser, and it can cause high CPU usage. Each AJAX request loads the full WordPress back-end while circumventing all forms of caching.
The Heartbeat API by default polls the admin-ajax.php file every 15 seconds to do an auto-save. If you leave a tab open on your computer, that one post alone might generate 5,760 requests in a day!
This can be controlled by plugins.
Additionally, plugins can also cause admin-ajax.php to spike.
3. Your Theme And Content
Picking A High Performance Theme
You need a fast, lightweight, responsive WordPress theme where you can disable features that aren’t in use.
If your theme doesn’t serve scaled images, you will need to do an additional handling on that.
This is one reason why several companies that build ready-made affiliate sites use Thrive Themes.
I took the below GTMetrix shot from their demo site.
- PageSpeed: 39
- YSlow: 63
- Page load time 1.8s
- Requests: 55
As you can see, it already has CSS and HTML minified, it serves scaled images.
Once you set up image optimization and handle server-related issues like Gzip compression and browser caching, you have an above 90 score.
Reduce the number of external HTTP requests.
Each of these can have their own added latency based on the location of their server.
Just having a YouTube video on my homepage was adding 2.9s to the page loading time, which is the reason why I removed it.
Other type of HTTP requests come from Google Analytics, JetPack stats, etc.
Caching plugins can reduce these delays by hosting these scripts on your server and by DNS prefetch.
Limit Elements on Your Home Page
The concept here is simple. Your homepage is a key page of your site.
If you have 50 blog posts listed there, you will have 50 thumbnails all loading at the same time.
Since you want it to load fast, you can’t have 1,414 elements on your home page (like I did).
4. Speeding Up A WordPress Site By Image Optimization
If you don’t optimize your images, your site will remain slow.
It’s not uncommon to see sites loading images bigger than 1.5 MB. Pretty much all your images should be below 100k.
As the website owner, images are completely under your control, so if you can work out how to optimize images, you can have a great impact on the speed of your site.
To optimize your images, you should
- Resize the image and choose the good resolution
- Compress the image without losing quality
- Use next gen image formats, such as webp
I have tried several image compression tools.
The best free online (upload) tool I found is Squoosh (created by Google).
You can resize and compress at the same time, adjusting quality of compression.
You can select between .png, .jpg and a few more outputs.
I usually size my images to 1024 or 750 wide.
Here is an example image –
- Original: png, 1920×779, 1.03 MB
- Compressed: jpg, 1920×779, 134 kB
- Compressed: jpg, 1024×415, 53.5 kB
- Compressed: jpg, 750×304, 35.2 kB
If some of these steps seem annoying or complex, you can install a plugin (Unfortunately Squoosh has no plugin.)
I recommend that you test the optimized image in each case, because the advertised services are not always the best.
Warning: Always test these plugins on a few images to ensure compatibility with your theme.
Example: The Sqoosh screenshot just above
- Original was .png, 1024×448, 363 kB
- Compressed .png, 1024×448, 42.45 kB
The plugin also does webp and it achieves a 70-80 percent reduction in size.
Downside: It takes a few minutes to optimize the uploaded image.
The optimization happens automatically on upload and you will have options displayed in your Media Library:
Pricing: All plans start out as a FREE Account which comes with 25MB monthly plan on unlimited websites.
I found this plugin accidentally.
In contrast with other services, Optimole has a page where you can test your site and see how much you can save image by image (webp format).
It saved 50 percent on my already compressed image:
You also get your images served from an image CDN free of charge. Works with more than 200 server locations worldwide on the paid plans, 40 locations on the free plan.
Pricing: Generous free plan up to 5,000 visits monthly, then $6 up to 20k monthly visitors.
Smush – Compress, Optimize and Lazy Load Images
Smush by WPMU Dev automatically compresses images on upload and can also be used to compress and optimize your older image files. You can also set maximum image resolution, and your images will scale down to more reasonable sizes while being compressed.
The free version of plugin doesn’t require you to create an account to use their API key. The bulk optimization feature allows you to optimize up to 50 images at a time, and you can rerun the bulk optimizer to compress more images.
The free version of the plugin doesn’t perform that well.
ShortPixel has lossless, glossy and lossy compression.
It also has a much better webP system than Smush, since Smush requires that you use their CDN to utilize webP.
When I made the switch from Smush Pro to ShortPixel I did run a test and saw a slight reduction in image sizes with seemingly slightly better quality (based on my own eyes, not really scientific).
This plugin achieves a 20-30 percent reduction in size.
A friend was using the paid plan of this plugin and I wasn’t too happy with them.
While the free Squoosh tool compressed an image from 1MB to 87k, Kraken’s super paid plugin could only compress it to 690k.
“When it comes to the message I understand that you have found the alternative and savings were higher with the mentioned app.
“Difference in result after compression depend on a variety of different factors. We are always striving to provide the highest possible amount of savings that will at the same time not affect the quality of your images.”
Pricing: No free plan. 2GB costs $9/month.
Using Image Optimizer And (JetPack Photon) CDN Together
Warning: Make sure you don’t double optimization services.
E. g. I found out that Thrive Themes has Kraken connected as its built-in image optimizer. If the option is enabled, it automatically uploads the image to Kraken and retrieves the compressed version.
JetPack also has image optimization.
JetPack free plan has a CDN to serve your images only.
At this time I don’t recommend the use of JetPack image optimizer. My first clue came when I started to see images showing up corrupt like this:
The problem came up again when I used it together with Imagify image compressor plugin.
Imagify will optimize your images locally (the copies which are on your servers).
Since your images are served by Photon CDN, and it’s not possible to invalidate their cache you won’t see the optimized images.
I checked JetPack’s support thread and their representative said,
“At this time, you have to contact us to clear it, and we can only clear one image at a time.”
Therefore I recommend you completely disable Photon.
5. Use of Caching Plugins
Caching can reduce your TTFB by a as much as 90%.
Good caching plugins take care of a lot of the stuff mentioned above and in GTMetrix.
But caching can also break your site.
Therefore the most important rules in using optimization and caching plugins are the following:
- Never turn on the same function in two plugins
- Always switch on one function at a time. Then clear the cache, let it preload and check your site
- Use the plugin that is designed to work with your server’s existing caching mechanism
Caching plugins instruct the server to store some files on disk or RAM. Therefore, it can remember the content it’s been serving in the past. As a result, your web pages load much faster from cache, because the data doesn’t need to be processed again.
5A. W3 Total Cache
W3 Total Cache is one of the most popular plugins in the WordPress plugin library and popularity is a proof of quality.
It is a free, open-source WordPress caching plugin with millions of installations.
All of the features are included with the base plugin, with no upgrades.
Works with almost all servers, supports SSL.
The CDN works with the media library so that you’re able to see how well your images are being optimized.
Minification and compression are provided, along with caching of your database, objects on your disk, and posts.
The main downsides:
- The backend settings are quite a lot and difficult to understand
- No official documentation
- No WebP support
5B. WP Super Cache
WP Super Cache is free and open-source, with no upgrades. It also has millions of installations.
It is easy to set up, allowing for the compression of pages, simple caching, cache rebuilding, and CDN support.
It also has built in garbage collection.
There are three caching modes, from Simple to Supercache. This makes it possible for all skill levels to speed up their sites.
The main downsides:
- No official documentation
- No WebP support
Hummingbird was created by the WordPress speed specialists (WPMU Dev) that also created Smush image optimization, therefore these two were designed to work together.
HummingBird makes your website and boosts Google PageSpeed Insights with fine-tuned controls over
- file compression,
- minify for .CSS and .JS,
- Lazy Load integration
- use gzip for HTML, JS, CSS
- database cleanup
- disable WooCommerce cart fragments
- Prefetch DNS Requests
- Cloudflare integration
- page caching
- browser caching
- gzip compression if used with Smush.
The plugin has an advanced Asset Optimization mode where you can literally instruct to compress or not every single CSS and JS file, therefore you can pinpoint if one of these break your site.
Hummingbird will scan your site, find files that are slowing it down, and provide tips and fixes for making your site run at top speed.
I was using this plugin for a while and I was happy with the speed increase.
For $49 a month, WPMU Dev offers a platform that includes managed hosting, HummingBird Pro, Smush, security plugin, WordPress support,
5D. WP Rocket
WP Rocket is the best plugin I tried and it has a simple user interface and quick setup.
- page caching
- separate cache for mobile if needed
- set cache lifespan
- prefetch DNS requests
- preload cache
- exclude from cache
- minify and combine .CSS and .JS,
- Lazy Load images, iframes and videos
- database cleanup
- CDN integration
- Heartbeat control
- use gzip for HTML, JS, CSS
- Self host Google Analytics and Facebook pixel
- Varnish integration
- Cloudlare and Sucuri integration
- automatic browser caching
- automatic gzip compression.
WP Rocket integrates with Imagify to serve your images using WebP.
It doesn’t have a free plan, only a 14-day money back guarantee. There are three payment plans:
- one website is is $45,
- three websites at $99
- and unlimited websites for $199.
You technically only have to pay for a one-time fee, but the support and updates are included if you keep the payments going for every year.
6. Which CDN Should You Use?
CDNs mirror copies of your website’s files and images on servers all around the world.
So if someone from Australia accesses the site, it gets served from an Australian server. If someone from India accesses the site, it gets served from an Indian server.
There are two different types of content delivery networks:
- Traditional CDN
- Reverse Proxy CDN
Traditional CDNs cache a copy of your content.
A reverse proxy CDN intercepts all incoming requests and acts as an intermediary server between the user and your host. This is one reason why you have to point your DNS directly to these providers instead of your host.
CloudFlare is a commonly used CDN. It works as a “reverse proxy”, masking the origin server’s IP and providing DDoS protection. Other features include:
- Page optimization features like minification
- security features like detecting possible intrusions
- free and automatic SSL certificate (Let’s Encrypt)
- and of course, it works as a CDN
I personally don’t like it, because it is extremely complicated to set up.
When I set it up (free plan), I had SSL certificate problems to troubleshoot (insecure site message in browser).
The free plan doesn’t allow you to upload your own SSL.
Additionally, the DDoS message with its ugliness and extra 5 second loading time annoys customers.
Per Matthew Woodward’s test CloudFlare decreased load time by about 14 percent.
I am currently using Bunny CDN on this site.
It integrates with WP Rocket and is very inexpensive – costs $0.01 for 1 GB traffic.
It has a 2-week free trial
A budget alternative to CloudFlare is MaxCDN. This seems to a popular service when talking about paid CDNs.
It’s a traditional CDN service, different from Cloudflare. It will only make a copy of your files to help you deliver them faster. It cannot interrupt the access to your server since it will simply replace the URL of your resources (images, .js, etc.) and load them from the server closest to the visitor. They can mirror your content in over 90 countries.
MaxCDN are the provider for a huge range of websites and services like StumbleUpon, Forbes and many major blogs.
Google’s low-cost CDN seems like a stable, cost effective solution – HTTP/HTTPS cache lookup costs $0.0075 per 10,000 requests.
7. Offloading Things Like Email
Emails have an impact on your server resources. With some hosts, abusing this could even get you suspended. This especially becomes a problem with those trying to send bulk emails.
If you send bulk emails, the following alternatives get the best results:
- Use a third-party solution that isn’t part of WordPress
- Use a transactional email service provider (e.g. SMTP) along with WordPress
Another advantage of using a third-party service is better email deliverability.
8. Don’t Obsess Over Scores
There are situations where you have to be able to leave it as it is.
Favicon loads late
We’re seeing a consistent pattern across speed tests on GT Metrix for a site where there is a 150-250ms gap between all resources loading and then the favicon request initializing. This extends the fully loaded time.
This is because the favicon is not needed to actually render the page, only to display in the title bar, so browsers postpone downloading it.
There is no point trying to fix this.
Favicon is generated with Real Favicon Generator.
Speeding up a WordPress site is by no means complete with the above, but I think it’s a good start.
All comments, observations are welcome.
Since I believe that the above is useful for all bloggers and webmasters, I want to ask you to please share this blog post and link to it from your applicable resource page.