In recent years, the good folks at WordPress have made it easier to use their free software not just as a blog, but as the hub of a rich content management system (CMS), complete with static content and custom data types. Given that, it’s no surprise that Webmasters and businesses around the world are increasingly basing entire sites around the platform. (And did we mention the “free” thing?)
While WordPress runs decently out of the box, site operators who employ a few tweaks and follow a few rules of thumb will achieve much better performance in the long run. In this article, we look at the best practices that will keep your WordPress site humming efficiently.
Limit the Number of Plugins
WordPress plugins are great. With a few clicks, ordinary users can add complex functionality to WordPress that otherwise might have taken hundreds or thousands of hours of programming.
But plugins also present a performance danger. Each plugin in the WordPress plugins directory must be loaded every time a new request is made. Even if the plugin is disabled, it will still load. This performance “gotcha” particularly affects sites on shared virtual hosting systems (e.g., Dreamhost, HostGator). Performance degradation can be dramatic on shared hosts; in some situations, user requests may never finish completing.
The number of plugins that will cause a site to slow down will vary based on a variety of factors. The author has been told by representatives of HostGator that they encourage customers to limit the number of installed plugins on their virtual hosting service to seven. Webmasters should select the WordPress plugins they employ carefully, and use a load testing service to measure the performance impact of any new plugins that they add to their system.
Which WordPress plugins should you keep? The best plugins are those that:
- provide critical functionality that isn’t available in the core WordPress product; and
- cannot be implemented by making changes to your WordPress template.
For example, while a social media plugin may be a fast way to add a Facebook “like” button to every post, it’s also something that a savvy WordPress user can work into their current template. By contrast, an anti-spam plugin such as Akismet provides behind-the-scenes processing that goes above and beyond a simple template change.
Use a Caching Plugin
Speaking of necessary plugins, let’s talk about caching. As discussed in previous articles, there are many different types of caching, including client-side file caching, application caching, data caching, and PHP opcode caching. WordPress does not provide any native controls to control these various aspects of caching. Fortunately, a number of plugins exist to fill the gap.
Currently, the best plugin for all-around caching on WordPress is W3 Total Cache. W3TC can be used to configure many of the caching options we’ve discussed in previous articles, such as:
- Critical client-side cache control headers, such as the Expires, Cache-Control, and ETag headers
- Server-side caching of compiled WordPress pages
- Caching of database objects
- Applying Minify to Javascript files to reduce the number of scripting files downloaded
Verify the Performance of Individual Plugins
While a plugin may be convenient, that doesn’t mean it’s been coded correctly. A “cool” plugin that generates expensive or redundant calls against the WordPress database can drag your site’s performance into the mud. (Some plugins, as as the YARPP related posts plugin, are known CPU hogs.) Try disabling plugins selectively, and use a load testing tool to measure whether there is a noticeable benefit to the performance of your site.
Optimize Your WordPress Template
An inefficient WordPress template can drag down the performance of your WP-powered site. Switch your blog to a standard theme, and see how it performs (especially under heavy loads generated through load testing) compared to your site’s main theme. If it’s significantly slower, your theme may benefit from one or more of the following enhancements:
- Consolidate redundant and expensive database calls.
- Consider removing code that generates calls to other Web sites. On the server, this includes things such as RSS feed plugins. On the client, it may be code such as social media scripts that display the number of likes or shares for a given article.
- Remove Javascript files that are no longer being used.
- Offload static files such as Javascript and CSS to a separate server, as described on the WordPress.org Web site.
Optimize Apache
WordPress can only be as efficient as the Web server that hosts it. If you run WordPress off of a non-shared Apache server, review and apply our Apache performance tips.
Conclusion
While WordPress reduces much of the complexity involved in running a Web site, it can complicate performance. The platform’s very ease of use can lure users into deploying template changes and using plugins that can cause slow response times, especially under high load. Fortunately, most of these performance traps can be avoided by minimizing plugins, deploying a caching solution, optimizing WordPress code, and load testing on a regular basis.