Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flushing output before rendering completed in Symfony/Twig

Is it possible to flush output buffer before rendering completed? My point is to improve perceived performance of the website.

E.g. there is a big table (like 5 000 rows) in admin interface to be rendered. I'd like to tell Twig/Symfony to flush output right after </head> has been rendered, so the browser can start downloading styles/javascript, and then flush output after every 500 rows.

like image 479
Jakub Kulhan Avatar asked Jan 11 '23 03:01

Jakub Kulhan


1 Answers

What you want to use is the Twig {% flush %} command which is the equivalent of the PHP function flush(). Place it right after the </head> tag in your template for it to send the current buffer to the browser. Each time you call it it will output any output buffered so putting it in a loop will work fine.

For more info see the docs.

like image 82
cryptic ツ Avatar answered Jan 16 '23 20:01

cryptic ツ