Speed up response. Buffer in ASP

Source: Internet
Author: User

For 1 to 256
Yongfa365 = yongfa365 & "<! -- In this example, the front side is generated with 256 characters so that real-time output can be achieved. -->"
If Len (yongfa365)> = 256 then exit
Next
Madebasic ()
Mademodel ()
Madeindexblogitem ()
Response. Write "1/6 all templates are generated <br>" & yongfa365
Response. Flush ()
Madeindex ("calendar ")
Response. Write "2/6 date index generation completed <br>"
Response. Flush ()
Madeindex ("category ")
Response. Write "3/6 category index generated <br>"
Response. Flush ()
Madeindex ("blog ")
Response. Write "4/6 total index generation completed <br>"
Response. Flush ()
Maderss ()
Response. Write "5/6rss generated <br>"
Response. Flush ()
Madeitem ("all ")
Response. Write "6/6 allArticle<Font color = Red> OK is generated. </red>"
Response. Flush ()

The above section dynamically generates a static file segment for the backgroundCodeTo make it visible to youProgramWhere is the execution? No response was added before. flush () only looks at the progress bar in the IE status bar. It feels so depressing, with response added. after flush (), I feel like the word "great". Below is a collection of reference materials from the Internet:

I don't know how much you know about buffer. Many people are vague about this concept, especially in ASP. Many beginners rarely use this statement when writing ASP programs. Next I will talk about the usage of buffer and Its Role in ASP programs.

I. Buffer

Buffer is called a buffer, because it is not only a noun, but also a verb.
The buffer zone stores a series of data. The data obtained by the client can be directly output from the execution results of the program or the buffer zone. However, the two methods differ in speed: in the Web, when an ASP program is requested for a small number of times, there is basically no difference between the two, at least we do not feel it. However, when many people request an ASP program, the speed may be different. If there is no buffer, the result obtained by the client of each person requesting the ASP program is the result obtained by executing the ASP program once. If the ASP program is buffered in advance, the result obtained by each client is the result of the buffer, not the result of executing a program. For example, if 1000 users access an ASP page at the same time, if the ASP program is not buffered, the program will be executed one thousand times, so that the server load will increase, this slows down the page opening speed of the client. If the ASP program is buffered, the results will be different. Each client obtains data directly from the buffer zone, the server will not increase the number of program executions because of the increase in access, so the client can open the page faster than in the previous case. This is the benefit of buffer.

Ii. How to buffer ASP programs

This problem is actually very simple, as long as the first line of the ASP program is added:
<% Response. Buffer = true %>
You can.
This statement indicates whether the output page is buffered. When the attribute value is true, the server will not send any information to the client until all programs are executed or
<% Response. Flush %> or <% response. End %>
Statement to release the buffer information.
Use response. buffer = true, response. flush can improve the browsing speed. If a page is response. buffer = false: 30 data records are transferred. If 100 users browse this page, 3000 data are transferred back and forth, which seriously affects efficiency. If response is set at the beginning. buffer = true, divide the entire page into several groups, and match response in appropriate places. flush to greatly improve the user experience.

3. Why does it feel useless sometimes?
For example:
<%
'Warning: It's okay. Don't run this.
For 1 to 10000
Response. write "<B> <center> <font color =" "# ff0000" "> I am www.yongfa365.com" & I & "</font> </center> </B>"
Response. Flush
Response. Clear
Next
%>
It takes only half a day to come out, and a bunch of items come out, and then come out one by one.

Cause:

Response. Flush (). It sends the compiled data in the buffer to the client first.
However
The flush content must contain at least 256 bytes. That is, only when the compilation generates at least 256 bytes of data can the information be sent to the client and displayed after response. Flush () is executed.

Clear Method
The clear method deletes all HTML output from the buffer. The clear method only deletes the response body without deleting the response title.
Syntax
Response. Clear
Note
Call response. Clear to clear the data output by the face on the front of this page. If the Program sets response. contentencoding, response. Clear sets the encoding method to direct transmission.
Apply to response object

Iv. Summary

Although the buffer attribute of response can increase the page display speed, what should be done. If you are creating an ordinary personal homepage with a low access volume and no complicated execution programs, it is not very important to use this attribute, it takes some time to buffer data, but we don't feel it. But if you are creating a large forum or a product demonstration or other business site, and the traffic is high, we recommend that you add <% response. buffer = true %>, because this allows the customer to obtain more data within the effective time.

Appendix:

This is usually included in the header of the 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"
To prevent caching.

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.