Speed is an increasingly important demand for today’s websites. Studies have shown that today, 25 percent of users will only wait two to four seconds for a page to load before leaving. At WP Engine, we’re in the business of making your site blazing fast so your content can reach your audience quickly and effectively. We’ve put together a list of ways you can improve the time it takes for your page to load.
In general, site performance can be broken down into two main segments:
- The amount of time it takes the server to generate the page
- The amount of time it takes the browser to download the page
In this blog post, we’ll be focusing on the things you can do to improve how quickly the server is able to generate the page to send to the web browser.
1. Leverage Page Cache
One of the main differences between HTML and PHP sites is that with HTML sites, the web browser simply has to request a static file to serve the page. With PHP (which WordPress uses), the page is dynamically built when it is requested by executing PHP code and database queries. While this means PHP-based sites are computationally more expensive on a server, it also means that the type of content your site can serve is more dynamic and personalized to your users. This is why many choose to use WordPress as a content management system (CMS).
Since it’s more taxing on your server to build a dynamic web page for each user that comes to your site, we highly recommend using a page cache system. This means each page that’s requested is stored as a static file in a caching layer on your site’s server, to serve to visitors for a specific period of time. This offloads much of the work the server has to do to generate your site’s pages when they are visited.
At WP Engine, we use page cache as part of our Evercache system, with a cache expiration time of ten minutes. This means that when a page is requested for the first time, it spends time generating the page with PHP and database queries and then stores a copy of that page in cache. For the next ten minutes, when that page is requested, it will be served from the cache layer instead of regenerating it again. After ten minutes, the cache is purged and the process starts over.
2. Use Object Cache
Aside from generating the page with PHP, your WordPress site also depends on a database to create pages and store information. When information is requested from the database, running those database queries can also take more time and power on the server’s end.
When you use a layer of the object cache, it allows you to store WordPress database query results in the server’s memory. So instead of running a new request for the same data to be processed by the database each time, WordPress is able to get this information from server memory.
WP Engine uses an object cache layer to store repeated query results. All sites will have the option to enable this caching layer from their User Portal under Installs » Utilities.
3. reduce database bloat
Keeping your database in tip-top shape should also be a priority for your site. The less database bloat you have, the faster your site can perform. This means cutting down on things like post revisions, orphaned post/postmeta and comment/commentmeta rows, as well as reducing autoloaded rows in wp_options.
In WordPress, the wp_options database table has a lot of your site’s configuration settings like: siteurl, active themes, active plugins, cron jobs, and more. These are important settings which probably should be set to automatically load on every page.
By default, most options stored in wp_options are set in the “autoload” column to “yes,” which means they have to load on every single requested page. However, plugins or themes may be adding rows and transients to your wp_options table, which may not be information that needs to load on every single page.
It’s good practice to periodically check through your wp_options table to see if there are any rows added by themes or plugins which might be very long, and may be causing a delay in site load time.
4. Keep WordPress clean
WordPress is a very versatile CMS, but sometimes customization can be very costly to the amount of time it takes to load your site. It’s best to keep configuration files, like the .htaccess file and wp-config.php files, close to their default state. These files have to be loaded on every page load too, so reducing things like rewrites and server directives in the .htaccess file, in particular, can be helpful.
WP Engine offers the option to set redirects and rewrites in our User Portal. Redirects set here will be executed before the request is sent to be processed by PHP. This translates to less heavy lifting for the server to redirect the request.
5. Use Relevant plugins
Since WordPress is open source, there are thousands of plugin and theme options to choose from when it comes to your site. When you’re deciding on which plugin to use for a site function, check out the plugin’s page and see how often it’s updated, and how often support threads are resolved.
If updates are fairly frequent and the authors still seem engaged in support threads, this is a good indication that this plugin is being actively maintained. This is good because more updates often mean more optimizations to the way the plugin functions. It also means the authors are more likely to help patch any security vulnerabilities the plugin may encounter.
Using relevant plugins also means to cut down on the plugins your site doesn’t need or use. If a plugin is inactive and you don’t know when you would use it again, it’s best to delete it entirely.
6. USE A CDN
CDN technology is offered at WP Engine, which can be enabled right through your User Portal without using a plugin to rewrite your site’s source code. But other plugins can also integrate with CDN for minification or caching purposes.
There are also CDN options which involve routing your site through a reverse proxy and leveraging caching at this level. Offloading content through this type of CDN can be valuable for sites with extremely high levels of traffic. They allow for custom configuration of caching for pages and files as well if you want a more granular approach to caching. By using this kind of CDN, it helps offload a good portion of the server processing to cache it instead.
7. AIM FOR SCALABILITY
It’s also important to keep your site as cacheable as possible. Limit the amount of PHP actions and queries being called on your site. This means, reducing actions that have to be repeated on every page load, like a page-view counter or a share counter. Instead, try using caching settings for these features to only refresh them every few minutes, or every hour.
If your blog has many older archives of articles, this could also mean something as simple as being crawled by Google could add up to server load time, because of the number of uncached pages being requested. You can try increasing your cache-expiration settings in your site’s .htaccess file, to help ensure that fewer old pages are going to the server uncached.
About the Author
Janna Pyles is WP Engine’s Site Performance Subject Matter Expert. She has lived in Austin for the past four years and enjoys hiking with her dog, painting, and both technical and free form writing.