As an ASP programmer, you won't doubt the importance of improving the performance of your Web applications. In order to make your program run faster, you may have been busy optimizing the database or COM component. If you have done all of this, have you ever thought about improving performance by speeding up the display speed of the final generated HTML code in the browser? To the end user, if the page can be displayed faster, you will win more praise.
Improving the speed at which HTML is displayed in your browser can be achieved through some little-known techniques.
1. Use table nesting?
Establishing complex structures in the page is generally achieved by placing HTML tables on the page. If you want to create a page like this: This page has a top navigation bar, a left navigation bar, and a right content area. You can create this using a large table with two rows and two columns. In the first row, merge the two columns and insert a top navigation bar. In the left column of the second row, insert a table to display the navigation buttons. In the right column, place a table to display the actual content. (See Figure 1) The code generated by such a nested table is as follows:
<TABLE BORDER="0">
<TR>
<TD COLSPAN="2"><!-- content for top nav bar --></TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><!-- content for left nav bar --></TD>
<TD ALIGN="LEFT" VALIGN="TOP"><!-- content for body of page --></TD>
</TR>
</TABLE>
However, in fact, when the browser finds the <TABLE> tag, it does not immediately display the page on the screen unless it finds the corresponding closing tag </TABLE>. Therefore, if your entire page is in a table, nothing will be displayed until the last </TABLE> is received. In this way, the page will not be visible to the user until the entire file is downloaded. When the amount of page data is relatively large (such as search engine search results), this feature will cause temporary pauses. In order to prevent this situation, the page can be divided into many small tables during production. When the HTML code from each <TABLE> to the corresponding </TABLE> is downloaded, the browser will display it. From the visitor's perspective, the page appears gradually, part by part, more and more appearing on the screen. It feels like the display speed of such a page is faster than downloading the entire file and displaying it again.
Following this principle to study the previous example, the entire large table in the page should be divided into three separate tables. Use the first table to display the top navigation bar, adjust its width so that it is large enough to hold all the content, and complete it in a <TABLE></TABLE> block. In the lower half of the page, the second table from the left is lined up. Use a third table to hold the actual content. (See Figure 2) Because each part is a complete table, each part of the code will be displayed immediately after downloading. This way, the top and left navigation bars will stand out more than the rest of the page. The user will imagine that the page will start downloading at this time and will be displayed on the screen soon. This is much better than leaving the user facing a blank screen for an extended period of time.
The modified code is as follows:
<TABLE BORDER="0" WIDTH="100%">
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><!-- content for top nav bar --></TD>
</TR>
</TABLE>
<TABLE BORDER="0" ALIGN="LEFT">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><!-- content for left nav bar --></TD>
</TR>
</TABLE>
<TABLE BORDER="0">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><!-- content for page body --></TD>
</TR>
</TABLE>
2. Also remember to close other tags.
In the above example, we can make the page display faster in the browser just by closing the <TABLE> tag earlier. By analogy, there are some similar tags that have the same characteristics.
For example, generate <OPTION> tags for list boxes and combo boxes and <LI> tags for list items. Usually, ASP programmers access the database and send data into the list box or combo box created through <OPTION>. At this time, a closing <OPTION> tag is written in the code. Such a simple change can also make the page Displays faster in the browser.
Do not use code like this:
Do while not objRS.EOF
strOptionList = strOptionList & "<OPTION VALUE=""" & objRS("ID") &_""">"& _objRS("ProductName")
objRS.MoveNext
Loop
Response.Write "<SELECT SIZE=""1"">" & strOptionList & "</SELECT>"
To use code like this:
Do while not objRS.EOF
strOptionList = strOptionList & "<OPTION VALUE=""" & objRS("ID") & _ """>" & objRS("ProductName") & "</OPTION>"
objRS.MoveNext
Loop
Response.Write "<SELECT SIZE=""1"">" & strOptionList & "</SELECT>"
Don't use code like this:
<UL>
<LI>Apples
<LI>Oranges
<LI>Bananas
</UL>
Use code like this:
<UL>
<LI>Apples</LI>
<LI>Oranges</LI>
<LI>Bananas</LI>
</UL>
Now take a look, does your page display faster in the browser?
Please do not underestimate the importance of these changes in improving the performance of ASP applications. Perhaps, in the "Tips and Tips" type of books or online materials you can find, there is rarely any mention of optimizing HTML code to make your program run faster. However, applying these technologies in practice can indeed greatly improve program performance.