Skip to content

Cloudflare’s full html edge cache with Magento cookies bypass

We are trying to setup magento edge cache with cloudflare including html. The url route of bypassing cache on urls alone e.g. /customer, /admin, etc doesn’t really work bcoz e.g. when a customer logs in the page shown to him is still homepage.

In summary: we managed to get it working pretty well by implementing full cache including html but bypassing edge cache in the presence of certain cookies which were:

phpsessid
private_content_version
admin

We soon realized that by simply visiting a product url without even being logged in Magento introduced PHPSESSID so cloudflare stopped delivery from its’ edge servers. Then we tried setting up cloudflare edge cache including html once again by disallowing cache in presence of private_content_version and admin cookies only. This strategy seems to work as long as the visitor doesn’t add anything to its cart! As soon as the visitor adds anything to the cart the private_content_version cookie is introduced which forces cloudflare to go dynamic and stop delivering from its edge cache servers.

I have been studying that private_content_version has something to do with browser’s local storage & disabling full page cache removes it. But I fear any disabling of fpc on my part will terribly hurt response times for my logged in visitors.

Can anyone tell me what is the best solution to implement edge caching for Magento using cloudflare or any cdn? There is a cf help article on the matter but it again doesn’t address the failure of caching in case of cart addition. Frankly I don’t see why a solution cannot be implemented when cart data is pulled using ajax!