Caching Static HTML with Magento (version 1 & 2)

Cloudflare users on our Business Plan are able to cache anonymous page views when using Magneto 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.

Before someone logs into the the Magento admin panel or adds something to their shopping cart, the page view is anonymous and it may be possible to cache those requests so that Magento on your origin server doesn't need to constantly regenerate the HTML.

Before starting - be sure to ensure that Cloudflare is set to respect Cache-Control headers from Magento instead of overriding them with Cloudflare default values. In order to set the "Respect Existing Headers" option, visit the Caching tab in the Cloudflare Dashboard:

Scroll down the page to find the "Browser Cache Expiration" option, and select the "Respect Existing Headers" value:

With this in place, we can go ahead and set the necessary Page Rules to cache anonymous page visits. In order to do this we need to head to the Page Rules section in the Cloudflare dashboard:

Next we can go ahead and 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 our WordPress installation path, if your site is at https://www.example.com, the rule would be https://www.example.com. In my case, I have installed WordPress on https://junade.com, so my Page Rule should match https://junade.com/*.

We can then set-up the rules that we want to apply. "Cache Everything" will instruct Cloudflare to cache static HTML. When the "Bypass Cache on Cookie" rule matches the criteria we set, Cloudflare won't cache HTML (whilst static images and other files will still be cached). Depending on whether you're using Magento 1 or Magento 2, you will need a different rule:

Magento 1 external_no_cache|PHPSESSID|adminhtml
Magento 2     admin| PHPSESSID|private_content_version

Finally, setting "Edge Cache TTL" will define the maximum period of time Cloudflare should keep cached files before getting them back from the origin. Even after setting a long Edge Cache TTL time, you can still manually clear the cache before this time expires.

Next, just click "Save and Deploy" and we're done! If you're interested in verifying the content is being cached, please review: How can I tell if Cloudflare is caching my site or a specific file?

Enterprise Cloudflare customers can use Custom Cache Keys to take their performance further, contact your Customer Success Manager if interested.

Still not finding what you need?

The Cloudflare team is here to help. 95% of questions can be answered using the search tool, but if you can’t find what you need, submit a support request.

Powered by Zendesk