27-28 February, 2019, London
This week I’ve decided to better understand X-Magento-Vary cookie. In Magento 2 there might be more than one unique information presented to a user from the same URL.
X-Magento-Vary cookie is used by Magento 2 system to highlight that version of a page requested by a user has been changed. It allows having different versions of the same page stored in cache e.g. Varnish.
Any time a user performs an action e.g. Log in, subscribe to a newsletter, add to cart etc. this action changes the state of a system. This state is also known as HTTP context of a system.
The context is identified by various unique parameters which are used to generate unique md5 hash value. Once generated, a hash value is set into an X-Magento-Vary cookie parameter and sent back in an HTTP response.
The X-Magento-Vary cookie is set during HTTP POST or PUT request has been sent to a Magento application.
Varnish server configured as a front-end cache creates a new version of a page based on newly generated X-Magento-Vary cookie.
In order to generate a hash value, Magento 2 uses parameters which help to differentiate different versions of the same page and with different content on it.
Sometimes for one page stored in Varnish, you may have up to 200 different versions of the same page.
Max Pronko is an international Magento Expert, development consultant, motivational speaker and Magento award-winning developer. He is known for the educational development programs for organizations of all sizes and has positively affected thousands of people and organizations worldwide.
Subscribe to my Magento 2 tips and tutorials content.
Every week I send an interesting email directly to your inbox