Cloudflare Business plan customers are able to cache anonymous page views when using WordPress using our Bypass Cache on Cookie functionality. This allows for static HTML to be cached at our edge, with no need for it to be regenerated from request to request. This tutorial will help you set this up with WordPress and WooCommerce.
Enterprise Cloudflare customers can use Custom Cache Keys to take their performance further, contact your Customer Success Manager for more details.
Before starting - be sure that Cloudflare is set to respect Cache-Control headers from your origin web server; otherwise, you may find Cache-Control headers are overridden by Cloudflare with the value set in the Browser Cache Expiration option. In order to set the Respect Existing Headers option, visit the Caching app in the Cloudflare dashboard:
Scroll down the page to find the Browser Cache Expiration option, and select the Respect Existing Headers value:
Once this is done, set the Bypass Cache on Cookie rule. You can do this in the Page Rules app in the Cloudflare dashboard:
Next, click the Create Page Rule to set-up static HTML caching on our site.
The first step is to actually set the page rule to match your WordPress installation path. If your site is at https://www.example.com, the rule would be https://www.example.com.
In the example here, WordPress is running on https://junade.com, so the Page Rule should match https://junade.com/*.
You can then set up the rules that you want to apply.
Cache Everything will instruct Cloudflare to cache static HTML.
When the Bypass Cache on Cookie rule matches the criteria you set, Cloudflare won't cache HTML (whilst static images and other files will still be cached). Depending on whether you're using raw WordPress, or WooCommerce, you should use one of the configurations below:
|WordPress with WooCommerce||wp-.*|wordpress.*|comment_.*|woocommerce_.*|
Finally, setting Edge Cache TTL will define the maximum period of time Cloudflare should keep cached files before getting them back from the origin web server. Even after setting a long Edge Cache TTL time, you can still manually clear the cache or use our WordPress plugin to automatically manage cache purging.
Next, click Save and Deploy and you're done!
Additionally, by using the Automatic Cache Management feature of the Cloudflare WordPress plugin, you are able to automatically purge the cache for your site after your site changes (i.e. changing/customizing your theme or editing, deleting or creating a post, attachment or page).