28 Tips to improve ASP performance and appearance (15-21)

Source: Internet
Author: User
Tip 15: Batch inline scripts and Response.Write statements
Tip 16: If the page takes a long time to complete, use response.isclientconnected before executing
Tip 17: Use <OBJECT> tag to sample objects
Tip 18: Use TypeLib binding for ADO and other components
Tip 19: Use the browser's validation capabilities
Tip 20: Avoid using string concatenation in circular statements
Tip 21: Enable browser and proxy caching
Tip 15: Batch inline scripts and Response.Write statements
VBScript syntax <% = Expression%> writes the value of "expression" to the ASP output stream. If the response buffer is not enabled, executing each of these statements will write the data to the browser over the network with many small packets. This is a slow pace. and interspersed with small amounts of script and HTML will cause a switch between script engine and HTML, which can degrade performance. So, the trick is to use the Response.Write call instead of a tightly bound inline expression. For example, in the following example, each field in each row has a write operation on the response stream, and there are many transitions between VBScript and HTML in each line:
<table>
<% for each fld in Rs. Fields%>
<th><% = fld. Name%></th>
<%
Next
While not Rs. Eof
%>
<tr>
<% for each fld in Rs. Fields%>
<td><% = fld. Value%></td>
<% Next
</tr>
<% Rs. MoveNext
Wend%>
</table>
The following code is more efficient, and each row has a write operation on the response stream. All the code is contained within a VBScript block:
<table>
<%
For each fld in Rs. Fields
Response.Write <th>? & FLD. Name & </th>? & VbCrLf)
Next
While not Rs. Eof
Response.Write (&LT;TR&GT;?)
For each fld in Rs. Fields%>
Response.Write <td>? & FLD. Value & </td>? & VbCrLf)
Next
Response.Write </tr>?
Wend
%>
</table>
This technique is particularly effective when response buffering is disabled. It is a good idea to enable response buffering and see if batch Response.Write helps improve performance.
(In this particular example, a nested loop of the table body is established (while not Rs.) EOF ...) You can use carefully constructed GetString to replace. )
Tip 16: If the page takes a long time to complete, use response.isclientconnected before executing
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.