(+84) 463.28.7979

How to PHP Flush Buffer Early to Speed Website Loading


Did you know you can use PHP flush function to flush buffer early on your server to speed site loading.  I was reading this amazing Yahoo! guide about best practices for making web pages load faster, and though most other tips were common and practiced by most webmasters for faster site loading, this was new to me.

How does PHP Flush work?

When a page is requested on your server,  it takes 200-500ms for the backend server to  stitch the HTML page. While the  browser is idle as it waits, you can use PHP function flush() which allows you to send your partially ready 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 benefit is mainly seen on busy backends or light frontends. Learn more about PHP flush() function, its uses and limitations.

Where to Add PHP Flush in HTML

They recommend to add it right after the HEAD tags and before the BODY tags on your html page. This allows browser to fetch CSS and JavaScript files in parallel while the backend is still processing.

</head>
<?php flush(); ?>
<body>

Have you tried PHP flush on your server? Have you noticed a difference in site speed? Every millisecond counts, especially since site speed is a Google search engine ranking factor now.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>