Jakub Kulhan
Jakub Kulhan

Reputation: 1562

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.

Upvotes: 4

Views: 1834

Answers (1)

kittycat
kittycat

Reputation: 15044

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.

Upvotes: 9

Related Questions