Caching is an important aspect of any successful WordPress site, as it provides the ability to boost performance with little effort. This document aims to outline how caching – specifically page caching – works, with a particular emphasis on how page caching works for AMP-enabled sites.
What is caching? #
There are many different types of caching, including browser caching, page caching, content delivery network (CDN) caching, and object caching. In this post, we’re going to discuss page caching.
What is page caching? #
Page caching is a type of caching that stores a fully-rendered webpage the first time it is accessed by a visitor. Upon further visits WordPress (or an external page caching layer) can bypass re-rendering the full page and instead serve the previously cached version much faster. Page caching plugins often store the cached webpages in the persistent object cache, so page caching can be a further performance enhancement on top of persistent object caching.
Page caching is the type of caching that plugins such as WP Rocket, WP Super Cache, WP Fastest Cache, and other caching plugins perform.
Should I use a page caching plugin on my AMP site? #
Using a page caching plugin can be highly efficient for your WordPress site, and not just for AMP URLs. Having your site served to visitors in a static format can boost performance by eliminating the need for WordPress to re-render the full page with each request.
Note: To make the most of your AMP site we also recommend setting up a persistent object cache. This can help reduce database queries, which is different from caching related to the content of your siteThis is another great way to boost performance with minimum effort and zero maintenance once applied.
Aren’t AMP pages already optimized and cached? #
Another feature of AMP is that each valid AMP URL is eligible to be served from an AMP Cache. AMP Cache providers include Google, Bing, and Cloudflare. These services store static versions of your content, ready to be delivered instantly for visitors landing on your site from search. Any subsequent links that the user coming from search visits on your site are served from your (uncached) origin domain. In addition to the AMP Cache serving cached AMP pages, it also performs the same optimizations which are performed by the AMP Optimizer.
As users won’t always be served your site content from an AMP Cache, it’s beneficial to perform your own optimizations on your origin site, including an efficient page caching setup. This is especially the case for users who go directly to your site, and when you have mobile redirection enabled in Transitional/Reader template modes. As for non-cache optimizations, these are handled automatically by the AMP plugin since it includes the AMP Optimizer.
What if my content changes? #
Most caching systems have methods in place to refresh and serve the latest version of your content when a page is updated. Your page caching plugin can automatically empty the cache before regenerating a page for visitors based on certain conditions. These conditions may include time-based conditions, a page or post being updated condition, or a stale-while-revalidate approach – the ongoing refreshing of your content after each site URL visit, with the latest version of your content ready for follow-on visits by the next user.
You can check your current page caching plugin to understand how it performs and refreshes page cache, and identify if its default caching behaviour is not suitable for your site.
What page caching plugins should I use? #
There are several caching plugins that are compatible with AMP, and each provides different features and functionality. Some of the most popular page AMP-compatible caching plugins (based on number of downloads) include the below:
- WP Rocket: A popular commercial AMP compatible plugin that can speed up your site in just a few clicks.
- WP Super Cache: An Automattic caching plugin with over two million installs.
- W3 Total Cache: Another popular caching plugin which provides an AMP extension and persistent object caching integration.
- LiteSpeed Cache: An all-in-one site acceleration plugin. Be mindful of a combination of some non-default optimization configurations and their impact on AMP URLs.
- Breeze: A user-friendly caching plugin with Cloudways CDN integration.
- Cache Enabler: A simple, yet powerful caching plugin that requires minimal configuration.
- Cachify: A plugin that allows you to choose between caching via database, on the web server’s hard drive (HDD), or directly in the web server’s system cache.
- WP-Optimize: An all-in-one plugin that also provides support for object caching.
Please note that there may be configurations or extensions to some of the plugins above that may result in AMP validation errors.
Do I need page caching if I’m already using a persistent object cache? #
A persistent object cache is used for caching your database queries, while page caching is for your site content. Both caches can work in tandem and deliver efficient page speed improvements when configured correctly. In fact, page caches often use the persistent object cache for storage.
What do I need to consider before activating a page caching plugin? #
- Multiple caching solutions can conflict: If you have more than one page caching system in place, whether applied from your hosting provider and/or plugins, conflicts can occur that can result in poorer website performance. Having multiple page caches increases the risk that stale content will be served to users.
- Be mindful of configurations: Some features (that page caching or optimization plugins provide, like lazy loading, are not necessary in AMP URLs, as AMP already includes these features If you’ve applied various configurations, be sure to test your AMP URLs to ensure that all functionality is working as expected, with no validation errors.
- Your hosting provider may already have caching solutions: Some hosting providers include specific page caching solutions as well as persistent object caching configurations. If you’ve applied any page caching features at host level, it’s not recommended to install and activate page caching plugins. Please check your host’s documentation for recommendations for object caching and page caching.
- Caching policy: While many caching plugins provide a quick solution to ensure that page caching operates on your site some provide different configurations that may be worth considering.
- When things go wrong: If you see unusual behaviour with your AMP URLs after activating page caching on your site check for any non default configurations you may have applied. Some plugins allow you to reset to the plugins default state. If opening a support topic please include details of any errors encountered.
- Configure, test, and test some more: Many caching plugins will work out of the box, but it’s always good to test and compare your site as an end user after implementing page caching. Some sites with highly dynamic content may require different caching strategies, and some plugins may output unnecessary code on your site. Test to see what works best for you and do performance testing with tools such as web.dev or PageSpeed Insights.
The importance of page caching can not be underestimated when it comes to your WordPress site. If you want to ensure that your site loads quickly, consider implementing page caching on your site.