I have an event triggered on all pages to set a cookie. However, the cookie is created only on uncached page and I don't understand why.
Here, my event :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_predispatch">
<observer name="custom_cookie" instance="Namespace\Project\Observer\CreateCookie" />
</event>
</config>
And I used this class to create my cookie:
\Magento\Framework\Stdlib\CookieManagerInterface::setPublicCookie
I already tried with layout_load_before or controller_front_send_response_before but the result is the same.
If I desactivate the cache on all pages, all is working (but, of course, it's not a solution).
Can I used another event (triggered on all pages)? Or is there another way?