diff --git a/session.rst b/session.rst index 1594cc7eeb..9fec0e4644 100644 --- a/session.rst +++ b/session.rst @@ -265,6 +265,17 @@ It's common to use ``notice``, ``warning`` and ``error`` as the keys of the different types of flash messages, but you can use any key that fits your needs. +.. tip:: + + Accessing flash messages requires starting the session, which in turn + causes Symfony to mark the response as ``private``. In general, because + flash messages are meant to be displayed only once, pages that might show + them cannot reasonably be cached by HTTP caches. + + As an alternative, you can load flash messages asynchronously through + another HTTP request (for example, using a `Twig Live Component`_), making + the original page fully cacheable. + Configuration ------------- @@ -1881,6 +1892,7 @@ the example below: can use the Symfony save handler without side effects and that the session has not been started before Symfony is initialized. +.. _`Twig Live Component`: https://symfony.com/bundles/ux-live-component/current/index.html .. _`phpredis extension`: https://github.com/phpredis/phpredis .. _`DoctrineMongoDBBundle configuration`: https://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/config.html .. _`MongoDB shell`: https://docs.mongodb.com/manual/mongo/