Best Practices for Speeing Up Your Web Site from Yahoo includes the following recommendation:
When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush(). It 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.
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it 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 -->
Note the point at which the flush occurs here is after the head tag is written. This makes a lot of sense so the browser can begin loading images and scripts while the remainder of the page is rendered and served.
Is there a way to flush after the head (or any other part of the page) explicitly using ASP.NET?
When an ASP.NET application explicitly flushes with the Response. Flush API, it causes a synchronous send that blocks the ASP.NET request thread until the client receives the response data.
The Response. Flush method is used when you want to flush part of the content before the rest of the page. To have any effect response buffering has to be turned off, and you have to output the page content yourself using Response.
You should be able to put the following in your page between the end of the head and the beginning of the body statement:
<% Response.Flush(); %>
However, be careful here in the event that you are using a script manager or any other kind of control that will register itself for output in the head section of the html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With