tags: server
When a user requests a page, it takes about 200 to 500 ms for the backend server to put together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the flush() function. This allows you to send your partially prepared HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. The benefits are especially noticeable on busy backends or light frontends.
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to create and allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
... <!-- css, js -->
</head>
<?php flush(); ?>
<body>
... <!-- content -->
Yahoo!'s search engine research is pioneering and real user testing proves the benefits of using this technique.