From 99e0181715c0eae9f9087f69d782e38fd70d1d14 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 15 Sep 2025 13:37:14 +0200 Subject: [PATCH 1/2] Add a note that checking for flash messages defeats HTTP cacheability --- session.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/session.rst b/session.rst index 1426614e3a..8188081eb3 100644 --- a/session.rst +++ b/session.rst @@ -265,6 +265,13 @@ 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 means that the session must be started, which + in turn will cause Symfony to mark the responses as ``private``. In general, + since flashes shall displayed only once, pages that might display flashes + cannot reasonably be cached in HTTP caches. + Configuration ------------- From 7d3dc38c2dab794cd8f399b301121e2613e1789a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 17 Oct 2025 13:05:26 +0200 Subject: [PATCH 2/2] Minor reword --- session.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/session.rst b/session.rst index 8188081eb3..ba5f468e55 100644 --- a/session.rst +++ b/session.rst @@ -267,10 +267,14 @@ needs. .. tip:: - Accessing flash messages means that the session must be started, which - in turn will cause Symfony to mark the responses as ``private``. In general, - since flashes shall displayed only once, pages that might display flashes - cannot reasonably be cached in HTTP caches. + 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 ------------- @@ -1879,6 +1883,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/