This guide will show you how to take just about any WordPress site to a maximum 1-2 seconds load time. If you’ve selected resources (theme, plugins, etc) that are built from the ground up for speed and your hosting provider is as well, then you can reach fractions of a second load times per page. In such instances, sub-300 millisecond page load times are the norm.
What this guide will not do:
- Help you fix problems with your hosting provider’s configuration or issues with plugins or themes that could be heavily slowing things down. For example many plugins and themes make external resource calls that you cannot control, which will inherently bring down the speed of your site. Therefore you may need to disable parts of your website (theme, plugins, etc) in order for it to play nicely with your caching plugin. If you’re using themes and plugins that optimize for performance, then you’ll find that enabling caching will work perfectly without much fiddling.
- Allow you to have your cake and eat it too. If you love exceptionally high quality images that are each 1MB+ or not-sufficiently-compressed video files, then you’re never going to get top marks on website bench-marking utilities. Similarly if you’ve got a part of your site that loads dynamic content on every page load, you may need to turn that functionality off or find another way to load it for optimal performance. You may need to sacrifice quality and functionality for speed if you want top marks.
If you are comfortable with all of the instructions in this article, then you should do them all to improve the performance of your website. If you’re a basic user, it’s also OK to only complete the sections you’re comfortable with. You’ll still see a performance improvement, just not as much as when you are able to complete all options.
Some parts will provide massive load time improvements while others will be negligible. Some parts will make a synthetic speed test like Google’s PageSpeed or GTMetrix speed test think highly of your site but may not create a difference in real-world load times. Such is the nature of synthetic bench-marking tools.
- Oct 15, 2019: Split step 5 into 2 sections (now 5 and 6) — static cache generating in step 5 (which improves performance but doesn’t break websites) and optimization of resources in step 6 (which improves scores on things like Google Page Speed, but which can also break your website).
- Feb 4, 2019: Replace Better WordPress Minification with Autoptimize as recommended minification system.
- Jan 9, 2019: Add PHP 7.3 Info
- Dec 3, 2018: Reformatted post for better understanding of difference between browser cache vs. nginx->php-fpm direct mode. Use Plesk recommended rewrite rules for nginx.
- Jul 4, 2017: Added ShortPixel as an image compression option, reformatted post.
- Feb 20, 2016: Added commercial option, WP Rocket, as a great paid replacement for WP Super Cache + WP Minify.
- Jun 16, 2017: Added some hosting/server tips.
- Dec 25, 2013: Original Post Date.
Without further ado, here’s 9 things you can do to dramatically improve your website performance:
1. Use a web host that cares about performance
If your web hosting provider loads down their servers with thousands of websites or doesn’t know how to get the most out of their servers, then it’s inevitable that you’ll encounter frequent slowdowns.
If you’re on shared hosting, be sure your host artificially limits the total number of sites per server to ensure your site will have the resources it needs to perform well. If you have your own VPS, ask your host how it’s configured and what parts of the configuration are designed to ensure top performance. If their answer doesn’t include things like SSD storage, nginx or lightspeed web server, and custom optimized configurations to serve static cache files, then it’s time to find a better WordPress web host.
If you’re very concerned about performance then it’s recommended to obtain a VPS of your own to ensure your site has dedicated resources. We often recommend trying out our artificially limited shared hosting first and if you find you need even greater performance, you can always move on up to a VPS.
2. Use PHP 7 (with opcache)
You can take a look at some of the metrics here. With opcache enabled (it is on by default when using PHP 5.6+ in Plesk) you can see anywhere from a 2 – 4x improvement in site speed. And all you need to do is ensure your web host, theme, and plugins support the newer releases of PHP. That’s it! If they do then it should be a very simple flip of the switch to better performance. If you can use PHP 7.3, it provides as much as an additional 30% improvement in performance over 7.2 and earlier.
That sounds great… but how do I use it?
- First, log into Plesk
- Under the domain in question, go to “PHP Settings”
- There will be two dropdowns at the top of the page; one for PHP Version, one for the PHP Handler. For the version, try the latest version, then if you encounter issues repeatedly step down a version until the site works. If you do encounter problems with the latest release of PHP, ultimately your best bet will be finding the source of the issue and fixing it, like updating an incompatible plugin or theme, however we recognize that this isn’t always possible.
- Scroll to the bottom and click “OK” or “Apply”
3. Enable Gzip Compression
Meanwhile, if your caching plugin does not add these values to your .htaccess file, you can do so manually to add Gzip to your site:
This tells Apache to compress all compatible content before sending it – saving time and bandwidth!
Using Nginx only? Use this in your Nginx directives (not .htaccess):
4. Enable Browser Caching
In a later section we’ll talk about using a Caching Plugin for WordPress; any of these should also enable browser caching for you. That said, if you want to set up browser caching manually, here’s how you do it!
First it’s important to understand what exactly browser caching is. Ever have someone tell you to ‘clear your cache’ on your browser? That’s because modern browsers are configured to download copies of resources (HTML/CSS/JS/Images) to speed up page speeds on subsequent visits. By default, though, some of these items are set to ‘expire’ very quickly – which doesn’t help with speed much!
This is not recommended if you’re still developing your site. Please only apply this config when the site is live.
That said, if your site is live and you want to squeeze a bit more performance out of it, you can configure your server to tell visitors how long to hold on to certain resources.
Here’s how to do it with Apache using your .htaccess file:
This tells the browser how long to ‘hold on’ to various file types, and you can change those periods to your heart’s content.
If you’re using nginx-only mode:
Enter the following under Additional nginx directives to increase cache times for static files.
It’s important to note that you must uncheck “Serve static files directly by nginx” in Plesk when inserting this rule: The static files nginx setting must be unchecked because this specifies the same thing — that nginx must respond to these types of files — except ours has the increased expiry time (the important part). If you leave the nginx rule enabled it will take precedence because it comes first, and thus your cache expiry entry will not apply.
You may wish to extend the list of file types found between the parentheses above to include the full list as shown within the “Serve static files directly by nginx” rule so that they match in terms of exhaustive filetypes that this rule applies to.
5. Use a Server-Side Static Cache Generator
In our testing the best commercial option for this is WP Rocket and the best free option for this is WP Super Cache. Both will create static cache files for each of your site’s pages and posts and both will work exceptionally well with our custom nginx configuration that auto-detects the static files and serves those without the need to launch a heavier Apache and/or PHP process. The advantages we’ve found to paying for WP Rocket over free caching plugins are almost exclusively in the website code minification and optimization part of things. See part 6 of this guide below for more info on that.
These static cache generating plugins can allow your site to handle massive spikes in traffic without breaking a sweat even on our shared hosting services!
We’ve used these configurations to bring a site on shared hosting to around 100k daily unique views without any problems, and a site on its own VPS to over 500k daily unique page views at an average load of 1.0. If your host can’t keep up, check out our Canadian WordPress hosting options. Even better, with the optimizations described in this step, step 6 (optimizing), and step 7 (image compression), your site can go from a failing, or otherwise low, Google Page Speed score to a 90+, depending upon the theme and plugins used.
Here’s how to get static cache output from our two favourite caching plugins:
- WP Rocket: Here’s how to install and activate WP Rocket using their guide. Once activated, it will automatically begin creating a static cache.
- WP Super Cache: log in to your WordPress installation and go to Plugins > Add New. Install WP Super Cache and activate it. Head to Settings > WP Super Cache and select “Turn Caching On” and press the Update Status button. Click on the Advanced tab. Check off everything with “Recommended” next to it. Press the Update Status button. Scroll down to the “Expiry Time & Garbage Collection” section and set the interval to either once or twice daily, then press the “Change Expiration” button.
Open up a different browser than the one you’re logged in to WordPress with and load any page on your site. Then refresh the page. You should find the refresh is now significantly faster than the initial page load. This is not *only* because your browser has used that first page load to cache resources, but also (most significantly) because the server used that initial page load to create a static cache file that is then served on subsequent visits.
Enabling static page caching should not have any effect on your site’s functionality, but will dramatically improve the TTFB (time to first byte) of your website as the server will be able to supply each page much faster than before. The single exception to this is if you have dynamic data that changes on the site that does not use AJAX; that part of your site will not automatically update on every page load. If this occurs, talk to your website developer and ask them to change the feature so that it uses AJAX.
In part 6 below, you can read about how to configure either WP Rocket or SuperCache + Autoptimize to handle more aggressive optimizations that will dramatically improve your Google Page Speed score.
6. Use a Code Minifier and Optimizer Plugin
Generally speaking you want to stick to a single optimization plugin at a time, however WP Super Cache and Autoptimize are actually designed to work together. WP Rocket has the functionality of WP Super Cache and Autoptimize combined in that it both generates static cache files (as described in part 5 above) and minifies and optimizes the site code.
Autoptimize does work with WP Rocket, in that WP Rocket will simply disable its optimization functionality when Autoptimze is detected, however in most cases we’ve found it unnecessary as WP Rocket has the same functionality already built in. WP Rocket’s optimization functionality also tends to be better at not breaking websites than Autoptimize when features like minification and deferral of scripts are enabled.
When it comes to optimizing site code (like minification), which is often needed to obtain higher scores with Google Page Speed or GTMetrix, we’ve never been able to get W3 Total Cache or WP Fastest Cache (among others) to work as well as Autoptimize or WP Rocket’s optimization functions.
Please note: this is the stage where enabling some optimizations may break parts of your site, particularly if the theme, plugin, or custom code hasn’t been written to work well with optimization. If this occurs for you, please see the troubleshooting steps below to learn how to fix it.
If you haven’t completed part 5 above, install and activate WP Rocket using their guide.
- Enable mobile caching
- Minify – Activate for all
- Use the Critical Path CSS Generator to create your Critical Path CSS to put where specified. Failing to do that can cause some issues.
If you haven’t completed part 5 above, do so now, then log in to your WordPress installation and go to Plugins > Add New and install and activate Autoptimize
- Under the Extra tab, beside Google Fonts, try out the option to “Combine and load fonts asynchronously with webfont.js” as well as “Removing Query Strings”.
- Press “Save Changes”.
After enabling optimizations in either WP Rocket or Autoptimze, it’s possible you will see broken elements on the site, depending on plugins used, your theme, and a variety of other things. If you do, I suggest disabling each of the types of minification one-by-one until you see the problem go away, then enable everything again except the setting you identified that is causing the problem.
Per-Page: If you find only select pages having problems, you can alternatively disable the option causing problems on that page alone — edit the page and look for the “Cache Options” box.
If you’re an advanced user, then you can re-enable the setting that didn’t work for you, then use a web inspector to inspect the page and find out which file is causing the problem. Once you’ve found it, go into the WP Rocket or Autoptimize config and exclude just that singular file from minification. (This will likely decrease your page speed score — if you want to keep good scores, then the solution is described in the note below).
Note: in the majority of cases where a site breaks after enabling minification or footer-loading options, it’s because you’re using either a theme or plugin that are not written properly for performance optimization. You should identify which theme or plugin is causing the problem and either 1) change to a better equivalent plugin (if available), or 2) report the problems to the developer of the affected software.
7. Compress image files
This is only going to give you a small noticeable speed boost (unless you’re on a very slow Internet connection), but it can improve your Google page speed score a surprising amount.
Original manual method: Run all PNG files through a compressor then upload them overtop of their prior versions. You may not have these tools available, but I opened all PNG files in Photoshop and exported them for web. If you do this make sure that the files do not include Metadata as this can eat up large portions of the files — especially for icons.
[Update Jun 16, 2017]: We now use Imagify to handle this for us, all server-side. It’s a fantastic plugin provided by the same folks as WP Rocket that will automatically manage the compression of your images either as a one-shot deal or ongoing (it’s up to you!)
[Update Jul 4, 2018] Another option is the plugin ShortPixel, it works just as well as Imagify in our testing and also offers very fair pricing.
Check out all of our recommended resources here.
8. Using nginx direct to php-fpm on Plesk 11.5+ [Advanced]
[Note: this performance enhancement is only available to Plesk admin users. If you have a shared hosting account you cannot make this change. Only those with their own VPS and Plesk 11.5 or higher can do so.]
Note that if you do not already have support for php-fpm installed on your server, enabling it will require the use of PHP 5.4 or higher. Upgrading to PHP 5.4 should only be done after ensuring all PHP code is compatible.
As of Plesk 11, all web traffic is first picked up by nginx, a web server engine designed purely for performance. For compatibility with most web applications, by default it will pass most requests through to Apache for standard processing, but certain things it can handle faster are simply responded to by nginx rather than funneling to Apache.
With Plesk 11.5 we’re now provided the option to handle all PHP requests via nginx direct to php-fpm, bypassing apache. This is the same combination that those ‘premium’ WordPress hosting providers use to offer extreme speed improvements with their hosted WordPress installs. Here’s how to do it (note that you must be a Plesk admin user to see these options):
- Log in to Plesk
- Choose the Websites & Domains tab
- Click on the domain you wish to adjust server settings for
- Click the “Web Server Settings” icon
- Scroll down to nginx settings and check off all three options. Specifically the last one -> process PHP by nginx
At this point your WordPress install will work great if you do not have permalinks enabled. However if you do (which most WordPress installs should, at the very least for SEO purposes), then you’ll need to provide a little extra info to nginx to inform it how to handle seo and human friendly URLs. Without setting this info, most of your pages other than the home page will probably fail to load with a 404 error.
Under “Additional nginx directives” place the following rewrite code [source]:
This is the same location where you can add the custom nginx gzip compression code as well as the code to increase static resource browser cache lifetime, found earlier in this guide.
Configure nginx to load static cache files (WP Super Cache)
Remember above when we told WP Super Cache to use mod_rewrite to serve our cache files? This is pretty much automatic if you’re using apache because in a good quality hosting environment WP Super Cache will prompt you to automatically modify your .htaccess file to include the necessary mod_rewrite rules. However with nginx, we must configure them manually.
One thing to watch out for here is that the first nginx directive we entered to handle permalinks properly is replaced by the part that says “# all other requests go to WordPress” so make sure those are not used at the same time.
It’s important to note that you may have some issues with the supplied nginx rules if you’re using WordPress in a subdirectory install, especially if you have a ‘nested’ install (with WordPress in the base directory and another WordPress installation in a subdirectory). It can be done with a lot of tricky changes to the supplied rules, but it’s definitely easier on all counts if you either:
- Use a subdomain installation
- Use apache if you must use a subdirectory setup
The reason for this is that .htaccess files are completely bypassed by nginx and the nginx directives are used instead. Apache’s .htaccess files allow for very simple per-directory settings, and without a similar system for nginx it really doesn’t work nicely at all.
Configure nginx to load static cache files (WP Rocket)
We made use of this handy WP Rocket nginx config by generating a config (follow the installation instructions), then pasting the result into the advanced nginx configuration directives location in Plesk 11.5+. Note that we have made adjustments to the configuration that we’ve found have worked best for our environment; if you’d like to take advantage of our optimizations, look into hosting with Websavers! It’s also important to note that this configuration has gzip compression and static file cache time increases built in, so you don’t need those directives above. That said, you *should* need the “all other requests go to WordPress” part somewhere in the config 😉
9. Disable unused PHP modules [Advanced]
If you have full admin access to your VPS, you can actually disable PHP modules you don’t need. Less things to load into memory, less memory use, less intensive processing, and faster performance. This is very advanced stuff, though, so make sure you either know what you’re doing or aren’t doing it on a live server so you’re not breaking anything 😉
- Go to Tools and Settings in Plesk
- Under General Settings click PHP Settings
- Select the PHP version and handler you want to change settings for
- Toggle PHP modules off that you’re not using
- Click OK or Apply to save
Now go back to your website and make sure nothing’s broken! You may not know what modules are used in every aspect of your website, so there could be a fair bit of trial and error to get this right.