ASP Response.Flush Real-time Display progress _ Application Skills

Source: Internet
Author: User
Tags flush blank page
Write the program in writing by the ASP page generated static page HTML, if the simultaneous generation of a large number of pages, must have encountered the browser below the progress bar shows 3%,6%,10% slow growth of the long wait process. In this waiting process, you do not know which record the page has been generated, only Kango and so on.

If you know Response.Flush and response.clear, then you don't have to wait. Every time an HTML page is generated, it returns a message with Response.Write, prompting that the database record has generated HTML.

In this way, at the same time to generate a large number of pages, you are no longer lonely looking at a blank page but only the slow changes in the browser below the progress bar and daze, you can always know which database has been generated to record, even if there are accidents, such as panic, power outages, You also know which day the next build should start generating HTML again. Is it cool, this is a progress bar and more specific.

Oh, don't worry, we first look at the meaning of Response.Flush and response.clear.

Response the Flush method of the object, immediately sends the output in the buffer. If Response.Buffer is not set to TRUE, the method causes a run-time error. Syntax: Response.Flush NOTE: If the Flush method is invoked on an ASP page, the server will ring a request to keep the activity on the page. Applies to the Response object.

About buffer, here is a paragraph. The meaning of buffer from the English literal translation is "buffers", where we call it buffering because it is not only a noun, but also a verb.

A buffer is where a series of data is stored, and the data obtained by the client can be exported directly from the execution result of the program, or from the buffer. But there is a difference in speed: In the Web, when an ASP program is requested a few times, there is basically no difference between the two, at least we don't feel it. But when a lot of people request an ASP program, the speed can be different. If there is no buffer, then each client requesting an ASP program gets the result of an ASP program execution once, and if the ASP program is buffered beforehand, the result of each client is the result of the buffer, not the result of executing the program. For example, there are 1000 users access to an ASP page, if the ASP program does not buffer, then the program will be executed 1000 times, so that the load on the server back to increase, resulting in the client open page speed slowed; If the ASP program is buffered, then the result is not the same, Each client obtains data directly from the buffer, and the server does not increase the number of program executions due to increased access, so the client opens the page faster than the previous one. This is the benefit of buffer.

About the Response.clear,clear method deletes all HTML output in the buffer. However, the clear method deletes only the response body without deleting the response headers. You can use this method to handle error conditions. Note that if you do not set the Response.Buffer to TRUE, this method will cause a run-time error. Syntax: response.clear; applied to Response objects.

OK, want to realize the effect of immediate output, as long as in the loop inside the hope that the output of the message after adding Response.Flush and Response.Clear can be. Such as:

<%
For I=1 to 2000
For I1=1 to 3000
' Empty loops, extending each execution time
Next
Response.Write i& ")"
Response.Flush
Response.Clear
Next
%>

The above ASP statement, you execute, you will find output is one by one output, execute once, the output once.

But I saw someone on the internet say, "Very often, we find that even if we use Response.Flush (), we do not send the previous message to the client to display it." What is presented to us is still screen. After repeated tests, I came to the conclusion that the content of flush should be at least 256 bytes. That is, only the compilation produces at least 256 bytes of data to send the information to the client and display after the execution of Response.Flush (). ”

Very strange, the above I give the statement really is to achieve a display-by-show effect, and did not output 256 bytes in advance, you can save the statement as a notepad to run a look, the effect is displayed line by row. My views are only representative of Flymorn personal views, not to be diverted.

If you really need to output 256 bytes in advance, you can do the following:

<%
Dim Liji
For I=1 to 256
liji=liji& "<!--produces 256 characters first-www.piaoyi.org-->"
If Len (Liji) >=256 then exit for
Next
%>
If you have different views, or have different test results, welcome to discuss with me.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.