Speed and reliability are essential in running a successful WordPress site. A fast, well optimized site not only creates a great experience for your visitors, but it will also have a positive impact on your search engine rank positions (SERPs).
Of course, the opposite is also true, so in this article, we will be discussing our top recommendations on how to best optimize your WordPress site for speed and scale.
The items below are provided in no specific order. We have found that generally applying these practices results in improved site speed and resource management, allowing you to scale better.
While this overview covers the use of terminal to debug and confirm things like cache, some commands could be substituted by looking at the requested page header responses in Atomic.
This article covers the following topics:
Optimizing the Page Caching Layer (Most Important)
Here we’ll discuss what’s involved in reviewing and managing hits to the page caching layer of our stack, which is installed and enabled by default on every Pagely VPS.
Checking for Cache Hits
To confirm that page caching is working properly, look for the X-Cache-Status: HIT
header in the page response.
Via command line this would be:
curl -I -X GET http://www.example.com/ | grep -i "HTTP/\|Cache\|Cookie"
After running that command twice, it should give a response that looks like the following:
HTTP/1.1 200 OK
X-Cache-Config: 0 0
X-Cache-Status: HIT
Handling Cache Misses
If it shows X-Cache-Status: MISS
or X-Cache-Status: BYPASS
, something is causing it to be skipped. This is usually due to a PHPSESSID cookie being set, similar to the following:
Set-Cookie: PHPSESSID=dcdb03bb64771ce5c24557f51f784e24; path=/
Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/
Try to avoid setting a session cookie when the pages don't have to be dynamic. A helpful command to find what theme or plugin is causing it is:
cd ~/sites/www.example.com/
find ./wp-content/ -type f -name '*.php' -exec grep -H "session_start(" {} \;
Avoid Ajax POST/GET Requests to admin-ajax.php
Upon requesting the homepage, or other certain pages on the site, there are sometimes plugins or themes that make an XHR request to admin-ajax.php.
Under high-traffic load, these requests tend to overload the server resources due to POST requests not being cacheable. This means that a dynamic PHP worker will have to serve every single one of these requests and use up a lot of the server's CPU.
You can test URLs and view response headers in the Atomic UI. If it’s discovered that these requests are being made, find out which plugin or theme is causing them to occur. Once located, we recommend disabling or removing them altogether. It's more important for the site to remain up, rather than overloading the resources so no other visitors can visit the site.
Redis Object Caching - Transients API, Say No to MySQL
Highly dynamic websites need advanced caching solutions to perform well and scale. Object Cache Pro will offload excessive database queries being made into the Redis object store, speeding up and improving overall site performance.
At Pagely, we offer Object Cache Pro to all of our VPS customers, which can dramatically improve your WordPress site's performance.
HTTP/2 - Become One with It.
HTTP/2 is an update to the protocol by the Internet Engineering Task Force (IETF). You'll get a nice performance boost with compatible clients, and anything that doesn't support it will fall back to the old protocol gracefully.
The performance gain is achieved by only requiring one persistent connection to the server to load the website's assets.
Other benefits of HTTP/2 include:
- Prioritization of higher resources
- Header compression
- Multiplexing (multiple requests over the same connection)
To support HTTP/2, an SSL certificate will need to be installed on your application. Once that's done, you should see HTTP/2 enabled within your Atomic dashboard. See our guide on HTTP/2 support to learn more.
Nginx-Only Mode
Switching your site to Nginx-only mode can help alleviate load caused by too many dynamic PHP requests with a built-in pressure-release valve. What does that mean? Head on over to our guide for NGINX+Apache and NGINX-only modes for more in-depth information!
Helpful Tools/Commands
- Pingdom: You can see how long the entire site takes to load. This is helpful to see which assets (JS/images/CSS) take a while to load.
- Query Monitor: This plugin is useful in identifying slow queries on the front and back end. We recommend enabling the plugin as needed.
- NewRelic: We can connect New Relic so you can get some detailed reporting about your application performance.
- View your CPU and Disk performance using PressFORMANCE in Atomic.
- To view CPU and RAM live, you can use
htop
(via SSH)
- To view CPU and RAM live, you can use
- Atomic: Offers a focused UI for testing and reviewing response headers.
Alternatively, you can:- Check the headers of the site in your browser.
- Use curl to check the headers of the site:
curl -I -X GET http://www.example.com/
In the header response,
X-Cache-Status: HIT
could be used to verify if that page cache is hit.