Have noticed that sometimes my X-Magento-Vary cookie is set serving me up non cached pages. Removing this cookie allows the FPC to work fine again.

Not entirely sure when these should be set but have assumed that it gets set for a user that is logged in maybe with a different customer group and prices would change. At least this is how I would like it to work for me. Not entirely sure how this all works have looked as far at:


if ($subject instanceof \Magento\Framework\App\PageCache\NotCacheableInterface) {

This was the only instance of X-Magento-Vary I could find outside of the VCL. Was wondering where this is behaviour is controlled why it might be set for me and if there is a way to fix change this behaviour so that only logged in customers do not get served cached pages.


Been a while but this keeps creeping up on me and making my warmed up pages via scripts useless for some users. I have found a few causes of this so far and just wanted to quickly outline my experiencel.

The "vary" header set in response for page can include "User Agent", for me this was just copying and pasting bits into my .htaccess and not paying enough attention to what they were. For me this is not needed as my templates are responsive and I do not want to serve separate versions for devices. The vary header I believe should just be set to vary: Accept-Encoding and possibly run the warmup script for most common types e.g. Brotli, GZIP etc.

I also have another issue which seems to happen on my second store where the vary header is set due to a store being set. To workaround this my warmup scripts are now using the same "X-Magento-Vary" header via curl matching this store.

I found it helpful whilst debugging to see what is going on in the getVaryString() function within Magento\Framework\App\Http\Context;

public function getVaryString()
    $data = $this->getData();
    if (!empty($data)) {
        return sha1($this->serializer->serialize($data));
    return null;

This often helps me to find the reason as to why the X-Magento_Vary header is set. In my most recent case the above prints:

Array ( [customer_group] => 1 [PERSISTENT] => 1 )

So although I appear to be logged out a customer group is set and that is causing the vary header to be set. I do not believe this to be correct behaviour however as should be 0 for "NOT LOGGED IN" and not show any vary data.

This has further issues of serving say the wrong customer groups pricing even when logged out e.g. Wholesale prices will show as the vary header states that a customer group is set even for a logged out user.

1 Answer 1


This was due to persistent shopping cart I believe in the end. In the case of a persistent cookie being present I believe it is correct Magento behaviour to even maintain certain things like customer_group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.