Ignore/Strip Cookies for Varnish
Our WordPress setup sets multiple cookies (from WordPress itself, Google Analytics, CloudFlare, and Third-Party Ad Networks), so every page request after the first will have cookies in the request headers. Because of those headers, Varnish considers it a "Miss" in the cache and passes through to the back end.
We need a way to be able to tell Varnish which cookies to strip for the sake of caching; on our previous dedicated server setup, we simply stripped the Google Analytics and WordPress (non-login) cookies, and that increased caching significantly.

This is now live:
https://support.cloudways.com/how-to-include-or-exclude-cookies-from-varnish/
Along with including/excluding URLs:
https://support.cloudways.com/how-to-exclude-url-from-varnish/
Cloudways Team
7 comments
-
AdminCloudways (Admin, Cloudways) commented
@frihet
There is no need to exclude woocommerce provided cookies usually, bypassing cart url(s) should be sufficient to use.
By default common urls [cart, my-account, checkout|addons, add-to-cart, add-to-cart ] , which may/can make use of sessions have already been excluded form varnish cache -
frihet commented
I just checked with support, and the cookies for WooCommerce are not automatically added.
To keep track of cart data, WooCommerce makes use of 3 cookies: (exclude them)
woocommerce_cart_hash
woocommerce_items_in_cart
wp_woocommerce_session_( https://docs.woocommerce.com/document/woocommerce-cookies/ )
I have also excluded urls:
/cart/
/checkout/Additionally
-
AdminCloudways (Admin, Cloudways) commented
This is now live:
https://support.cloudways.com/how-to-include-or-exclude-cookies-from-varnish/Along with including/excluding URLs:
https://support.cloudways.com/how-to-exclude-url-from-varnish/Cloudways Team
-
frihet commented
Would like varnish at cloudways to become more compatible with cloudflare, google analystics and woocommerce by finding ways to strip out cookies that cause varnish misses.
Varnish is a powerful solution to reduce server load, but only if hits are above 75%. -
ryan commented
i'm looking to host a members-only buddypress site. pantheon says they now “whitelist” the [woocommerce and buddypress] cookies used in the code so Varnish knows never to cache or strip them."
https://pantheon.io/blog/buddypress-and-woocommerce-realz -
Test commented
Modern plugins set cookies. Disappointed that Varnish at Cloudways doesn't offer this option. Time to look elsewhere.
-
Michael Dorchain commented
Having more flexibility with the varnish VCL would really be great. Not only whitelisting cookies is a must but managing url exception is also necessary to fully use varnish.