Optimizing WooCommerce on Pantheon: Advanced Page Cache for WordPress

As the owner of a WooCommerce site, speed has a direct impact on your bottom line. The faster your site responds, the more your visitors will convert, and the higher your revenue will grow. Kissmetrics found 40% of visitors will abandon a site that takes more than three seconds to load.

WooCommerce, meet Pantheon. Pantheon’s new Global CDN serves your cached product pages in milliseconds from 40+ worldwide points of presence. Rather than passing requests all of the way back to WordPress, it stores a rendered version of a page in Fastly’s distribution network.

Pantheon's Global CDN is faster than traditional Varnish-based full page caching because it puts your WooCommerce site in close physical proximity to your prospective customers. Even in 2017, websites are still subject to the speed of light and limitations of physical hardware. Pantheon’s Global CDN saves up to hundreds of milliseconds of latency by distributing copies of your site around the world.

The Ideal Scenario: Advanced Page Caching

Is it magic? Not quite but it’s pretty close. Ultimately, the goal is to keep as many pages in cache for as along as possible. Serving data from the Pantheon Global CDN is always going to be the fastest way to deliver a product page to a potential customer.

The Pantheon Advanced Page Cache plugin is the intelligence layer between WordPress and the Pantheon Global CDN. It tells Pantheon’s Global CDN how long it can cache a given page, and when to purge the cache. Pantheon Advanced Page Cache is more advanced than traditional full page cache plugins because it uses surrogate keys to “tag” the cache with details about which posts (and other data) are present in the cached view. When a post is updated, the plugin purges only those views where the post is present, instead of a global purge (which is heavy-handed) or a purge based on common patterns (which is inaccurate).

Say, for instance, you sell back catalog DVDs on your WooCommerce site. Oprah mentioned your site, and you’re still riding out the increased traffic from the attention. As you handle orders and manage inventory, you want to keep the frontend of the site as fast as possible. “Cache is only fast when it’s warm”, so your technology goal is to avoid purging cache unnecessarily and keep the long tail of product pages in cache as long as possible.

Installing & Using the Pantheon Advanced Page Cache Plugin 

The Pantheon Advanced Page Cache plugin makes this all possible. After you install and activate the plugin, it begins to emit two key pieces of metadata with every request:

  • TTL (as Cache-Control), to communicate how long the CDN can serve the cache until it’s expired.

  • Surrogate keys, to describe what posts, terms, users and other data is present in the page.

On a product page, the headers might look like this:

$ http HEAD fearlessmovies.io/movie/mad-max

[...]

Cache-Control: public, max-age=604800

Surrogate-Key: post-166633 single

[...]

When searching, the headers might look like this:

$ http HEAD fearlessmovies.io/?s=mad+max

[...]

Cache-Control: public, max-age=604800

Surrogate-Key: search search-results post-166637 post-166635 post-166636 post-166633 post-269239 post-269240 post-255246 post-252695 post-232483 post-229668 post-189359 post-189212 post-179553 post-171460 post-171055 post-170977 post-170951 post-170963

[...]

604800 seconds (aka seven days) is a long time! Fortunately, with a high degree of confidence in our tagging and purging strategy, we can keep views in cache indefinitely. This includes product pages, search, topical landing pages, and the homepage.

Under the hood, Pantheon Advanced Page Cache inspects the main WP_Query to determine which posts (and their corresponding terms, etc.) will be present in the view. If you’ve built your theme using the standard WordPress theme architecture, this is a reliable way of determining the main data present on the page. If you want to supercharge your caching behavior, you can also pre-render secondary elements on the page and include additional surrogate keys. This pre-compute step is necessary so we know which metadata to include in the headers, which are sent before the template is rendered.

To purge the correct views when WordPress data is updated, Pantheon Advanced Page Cache listens to a well-defined set of actions (e.g. clean_post_cache). When the action is called, the plugin proxies the event along to Pantheon’s Global CDN, and the cache is purged only for those views with the post present. Pragmatically, with this tagging strategy, it’s much simpler to purge the cache with precision, than try to guess which views a post may be present on.

Don’t Delay: Enable Advanced Page Cache

Make your WooCommerce site fast, regardless of where your customers are visiting from, by upgrading to Pantheon’s Global CDN. Your bottom-line will see the benefit from millisecond response times and 40+ worldwide points of presence. Pantheon’s Global CDN is a free enhancement for every Pantheon site, and will eventually be enabled by default.

The Pantheon Advanced Page Cache plugin is available from the WordPress.org Plugin Directory. Hit us up with questions, feedback, pull requests and bug reports in the project GitHub repository — we’ve already seen some awesome contributions from early adopters.


You may also like: 

Topics WordPress Hosting, Website Technology, Speed & Performance, WordPress