Your full service technology partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

-Collapse +Expand ASP Classic Store

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicLanguage Det...   Print This     
  From the October 2015 Issue of Prestwood eMag
ASP Classic Language Details:
Response.Flush and Response.Buffer
Posted 13 years ago on 12/19/2006 and updated 4/10/2010
Take Away:

Response.Flush sends the contents of the buffer to the browser. This command is useful for showing a visitor something while slow loading pages load.


In ASP, the Response object sends output to the client browser. You can use the Response.Buffer property to indicate whether the page output is buffered. If buffered, all scripts on the page will finish processing unless you specifically call either the Flush or End method. You can set the buffer in IIS or in code using the Buffer property.

For example:

Response.Buffer = True

If the Response.Buffer property is set to True, the Flush method immediately sends all current buffered page content to the client. IIS then stops processing ASP code and waits for the browser to ping back (a very fast procedure). The use of Response.Flush is a fairly common technique for showing a page background image and page header nearly immediately to a visitor while the rest of the page is rendered. This gives visitors the feeling of a more responsive website.

Proper Use of Flush:

Response.Buffer = True
''' ...some code that outputs here (perhaps a header and body background image)

Note: If the Flush method is called, the server does not honor Keep-Alive requests for that page.

If Buffering is Off, Flush Returns an Error

If Response.Buffer is False, then Flush will return the following runtime error.

Response object error 'ASP 0157 : 80004005' 
Buffering On
/home.asp, line 15
Buffering cannot be turned off once it is already turned on.

Response.Buffer Default

In IIS 5 and above, the default for Response.Buffer is True. In IIS 4 and earlier, the default was False.

Redirects MUST come before Flush

However, once you've called Response.Flush, you cannot use Response.Redirect to redirect to another page. Therefore, all your processing that might lead to a redirect needs to occur BEFORE you call Response.Flush. I think that's okay, because your code is cleaner anyway.

This code will fail...

Response.Redirect "/"

With this error:

Response object error 'ASP 0156 : 80004005' 
Header Error
/aspsuite/estore/_opensupportaccount.asp, line 47
The HTTP headers are already written to the client browser.
Any HTTP header modifications must be made before writing page content.

Cookies and Flush

Because cookies must be written before any HTML output, you need to handle cookies prior to calling Response.Flush.

Calling Flush Multiple Times

You can use Response.Flush to show the top of your page so your visitor can start reading your page.
--Mike Prestwood

You can use Response.Flush to show the top of your page so your visitor can start reading your page. This is a common technique around tables. Because browsers render ONLY after an end table tag, it is a common technique to call Response.Flush after the table end tag and prior to starting a new table.

You can call Response.Flush as many times as you want. However, because the browser must ping back to the server, it is a best practice to limit the use of Response.Flush to just a few per page. You definately don't want to call it every time you loop through a table of say 1,000 records.


Share a thought or comment...
Comment 1 of 2

how to use response.redirect after using response.buffer

Posted 52 months ago

Comment 2 of 2
Hi, Response.Buffter = false; Response.Write("Some Message"); Response.flush(); the above code working fine in my colleague system, but in my system not working. Why?
Posted 36 months ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1191A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100421 Counter
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site:

©1995-2019 Prestwood IT Solutions.   [Security & Privacy]