Improve Page Cacheability to Optimize Speed
Cached requests, or cacheable requests, are pages on a website that are essentially static in nature and can be stored in memory to be served very quickly. Cacheability can be defined as the ratio of website requests that are served from cache compared to uncached requests, commonly referred to as dynamic requests. Increasing a website’s cacheability can be directly linked to a higher performing website that scales smoothly with increased traffic.
When a request for a page on a site comes in it is sent to the server for the code to be generated. This alone doesn’t cause much strain for the server, as it’s pretty easy to serve just one page. The stress becomes much more apparent when the server has to build multiple pages per second. Caching helps ease the strain on the server by storing the previously generated page code in cache.
When a page request comes to the server, it first asks whether the page is in cache. If the page is already in cache, it’s served quickly and easily to the visitor. If not, it’s sent to the server to be built and then served. On its way back it also stores a copy of that page within the caching layer. The next time a request for that page comes in, it can be served from the caching layer, instead of having to be built like new.
This lightens the workload of the server, which means it can handle way more traffic at once than it otherwise could. It also speeds up the site, because serving a page from cache is much faster than building it new every single time. This is the type of caching that our WP Engine page cache uses to help improve the site’s performance.
By default the WP Engine Page Cache™ holds on to the content it stores for 10 minutes. This means every 10 minutes, the process of storing a new “snapshot” in the caching layer repeats itself.
WP Engine also offer a layer of “object caching”, which caches the results of repeated queries to the database.
For example, in a redirect plugin, any redirects would be stored in the site’s database. The website would then require that list of redirects to load every time a page is loaded, by running a query to the database. The server first looks for the list of redirects in the Object Caching layer, to see if the results are already available.
If a saved query result doesn’t already exist in the Object cache, the query is run in the database and the result is stored in the Object Caching layer for the next time a page is loaded.
To find out more about this type of caching, read our Object Caching article here.
Cacheability is the percentage of visits to a website that are cacheable, compared to those which are uncacheable.
- Static content (files which rarely change) like CSS, JS, and images for example, are easily cacheable.
- Dynamic content like login pages, shopping carts, and membership-only areas are not cacheable because they require the screen to show something unique to each person visiting it. A saved “snapshot” of the page wouldn’t work in those cases, meaning those pages are “uncacheable”.
A higher cacheability score indicates a faster site, better search rankings, and a lower bounce rate as a result (making for a better overall experience for visitors).
Optimize Dynamic Content
Uncacheable, dynamic content is great in that it “personalizes” a website’s content to the specific visitor. However, generating this content new on every page load can be very taxing on the server, meaning the site won’t scale as well once it starts receiving a lot of traffic. Sites that limit the amount of content that needs to be compiled new on the server every time will always present a faster, better experience for visitors.
WP Engine has created a unique option within our proprietary page caching system to allow developers to create page variations for different types of users, while still caching pages. Learn more about how it works in our User Segmentation article!
One struggle developers have dealt with through the years is how to personalize content for different geographic regions, while maintaining the highest cacheability (and scalability). At WP Engine, we’ve come up with a solution for websites with worldwide markets: Our revolutionary GeoTarget system. This system allows a website to serve different content to different areas of the world: by region, zip code, country, and more. And it also works within our caching system, by separating each area into its own “caching bucket.”
This means, for example, when a customer from Canada visits the site, they can view the custom content created for Canadian visitors, and stores a copy of this content in the “Canada” cache bucket. Then, the next visit from Canada can view a cached version of the site, which is served quickly and doesn’t need to be compiled by the server. Then, when a visitor from the USA visits the site, their version of the page is stored in the “USA” cache bucket, for the next USA visitor to see the cached version. The same would be true of any region with custom content created on the website.
Cacheability is important because it increases the website’s speed, availability, and scalability. This section will cover some ways to increase cacheability.
WP Engine-Specific Recommendations
- Switch to the advanced network or Global Edge Security: Each of these upgraded networks leverage Cloudflare features that can increase cacheability by adding caching at a DNS level. Learn about advanced network here. Learn about Global Edge Security (GES) here.
- Use a CDN: CDN stands for Content Delivery Network, and in short, it helps serve and cache the site’s static, cacheable content from multiple worldwide server locations. This helps improve performance for every area of the world, and not just the visitors closest geographically to the site’s server. NOTE: When utilizing advanced network or GES, CDN is enabled by default.
- Use GeoTarget: For Business level plans and up, GeoTarget through WP Engine is available. This is especially important for sites which want to display different content dynamically to visitors from different areas of the world. Rather than using a third-party plugin which generates uncached results for different locations, try using GeoTarget instead.
- Customize Page Variations within Caching: WP Engine allows for users to create multiple page variations to show to different types of users within its page caching system. Learn more about User Segmentation and how to implement it.
- Increase Cache Expiration Time: Configure pages to be cached for longer periods of time to help ensure optimal cacheability and scalability on a site. Learn how to leverage browser caching with cache-control headers.
- Object Caching: Enable WP Engine’s Object Caching layer, which comes included with every plan. Learn more about object cache and how to enable it.
Recommendations on Any Host
- Reduce external resources: When calling an image, stylesheet, font, or other resource from a site that’s not hosted on the WP Engine platform, it’s subject to the caching settings (if there are any), from the server that external resource resides on. Whenever possible, call these resources from the site itself, so they can be served using the WP Engine caching layer.
- Drop login requirements: For sites with memberships, asking users to login to the site creates an uncached environment for users. This means the resources and pages of the site will not be utilizing the caching layer. Dropping the requirement to login can definitely help improve cacheability.
- Sites with higher traffic will see the most benefit to caching. If a site only receives a visit once every couple of hours, it would already be generating the page as new from the server every time, since our caching layer only stores that “snapshot” for 10 minutes.
- Plugins and themes which use PHP Sessions to serve dynamic content to customers may not function correctly, due to caching. Read more here.
- If there is a specific page (other than the site’s home page) which needs to be exempt from caching (like a custom login page, for example), contact Support through Live Chat–available 24/7–to request this. Learn more about custom cache exclusions here.
NEXT STEP: Learn how to brace for a surge of traffic