The application technique of Response.Buffer speed-increasing under ASP

Source: Internet
Author: User


For I=1 to 256
yongfa365=yongfa365& "<!--the main thing here is to have 256 characters in front, so that you can output--> in real time.
If Len (yongfa365) >=256 then exit for
Next
Madebasic ()
Mademodel ()
Madeindexblogitem ()
Response. Write "1/6 All templates Build complete <br>" &yongfa365
Response.Flush ()
Madeindex ("Calendar")
Response. Write "2/6 Date Index build complete <br>"
Response.Flush ()
Madeindex ("Category")
Response. Write "3/6 Classification Index build complete <br>"
Response.Flush ()
Madeindex ("Blog")
Response. Write "4/6 Total index build complete <br>"
Response.Flush ()
Maderss ()
Response. Write "5/6rss Build Complete <br>"
Response.Flush ()
Madeitem ("All")
Response. Write "6/6 all articles build complete <font Color=red>ok, finally finished </red>"
Response.Flush ()

The above for the background dynamic generation of static file a code, the purpose is to allow themselves to see where the program execution, before Response.Flush () just see the IE status bar in the progress bars, feeling good depressed, plus response.flush (), feeling a word "cool", Below is a collection of references from the Internet:

Do not know how much you know about the buffer, many people on this concept are relatively vague, especially in the ASP. Many beginners in the preparation of ASP programs rarely used this statement, I would like to say the use of buffer and its role in the ASP program.

First, Buffer

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.

Second, how to buffer the ASP program

The problem is really simple, as long as the first line of the ASP program is added:
<% Response.Buffer = True%>
It's OK.
This means that the output page is buffered, and when the property value is true, the server will not send any information to the client until all programs have finished executing or encountered
<% Response.Flush%> or <% response.end%>
statement, the information for the buffer is freed.
The use of Response.buffer=true,response.flush can improve browsing speed, if a page response.buffer=false, there are 30 data transfer, if 100 people browsing this page, there are 3,000 back and forth transmission, Serious impact on efficiency, if the start of the set response.buffer=true, then the entire page into several groups, in the appropriate place with Response.Flush, you can significantly improve the experience of visitors.

Three, why sometimes feel useless
Like what:
<%
' Warning: Okay, don't run this.
For I=1 to 10000
Response.Write "<b><center><font color=" "#FF0000" "> I am www.yongfa365.com" &i& "Yes </font ></center></b> "
Response.Flush
Response. Clear
Next
%>
Half a day will come out, and come out is a pile, and then only one of the next.

Reason:

Response.Flush (). He will send the data compiled in the buffer to the client first
But
The content of the flush must 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 ().

Clear method
The Clear method deletes all HTML output from the buffer. The Clear method deletes only the response body without deleting the response header
Grammar
Response.Clear
Comments
The call Response.Clear will clear the data that is exported earlier in this page, and if the program sets the Response.contentencoding,response.clear, it will also set the encoding to direct delivery.
Apply to Response object


Iv. Summary

Although the response Buffer property can improve the page display speed, but also to be divided into what. If you are making an ordinary personal homepage, the traffic is not very high, and there is no complex execution program, it is not important to use this attribute, because it will take some time to buffer the data, but we can not feel it. But if you are making a large forum or a product presentation or other business site, and the traffic is high, then I suggest adding <% Response.Buffer = True%> in the first line of the program, This allows the customer to get more data in a valid time.

Report:

This is in the file in the general verification code.
Response.buffer=false
Response.expires=0
Response.ExpiresAbsolute = Now ()-1
Response.AddHeader "Pragma", "No-cache"
Response.AddHeader "Cache-control", "Private"
Response.CacheControl = "No-cache"
Just to keep it from being cached.

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.