diff --git a/profiler.rst b/profiler.rst index ca3458bcf06..968fbb5728f 100644 --- a/profiler.rst +++ b/profiler.rst @@ -21,3 +21,4 @@ install the profiler before using it: profiler/profiling_data profiler/matchers profiler/storage + profiler/wdt_follow_ajax diff --git a/profiler/wdt_follow_ajax.rst b/profiler/wdt_follow_ajax.rst new file mode 100644 index 00000000000..cf76609f0ab --- /dev/null +++ b/profiler/wdt_follow_ajax.rst @@ -0,0 +1,40 @@ +.. index:: + single: Profiling: WDT Auto-update after AJAX Request + +How to Make the Web Debug Toolbar Auto-update After AJAX Requests +================================================================ + +For single page applications it would be more convenient if the toolbar +showed the information for the most recent AJAX request instead of the +initial page load. + +By setting the ``Symfony-Debug-Toolbar-Replace`` header to a value of ``1`` in the +AJAX request, the toolbar will be automatically reloaded for the request. The +header can be set on the response object:: + + $response->headers->set('Symfony-Debug-Toolbar-Replace', 1); + +Only Setting the Header During Development +------------------------------------------- + +Ideally this header should only be set during development and not for +production. This can be accomplished by setting the header in a +:ref:`kernel.response ` event listener:: + + public function onKernelResponse(FilterResponseEvent $event) + { + $response = $event->getResponse(); + + $response->headers->set('Symfony-Debug-Toolbar-Replace', 1); + } + +.. seealso:: + + Read more Symfony events :ref:`/reference/events`. + +If you are using Symfony Flex, you should define your event listener service in the +``config/services_dev.yml`` file so that it only exists in the ``dev`` environment. + +.. seealso:: + + Read more on creating dev only services :ref:`/configuration/configuration_organization`.