Improve the display speed of ASP programs

Source: Internet
Author: User
Tags closing tag insert first row
Program | speed | show

As an ASP programmer, you will not doubt the importance of improving the performance of your Web application. To make the program run faster, you may be busy tuning a database or COM component. If you've done all this, have you ever thought of improving performance by speeding up the final generation of HTML code in the browser? For the end user, if the page can be displayed faster, you will be able to win more praise.

Increasing the speed with which HTML is displayed in the browser can be achieved by some little-known technology.

1. Use table nesting?

Create complex structures in a page, typically by placing HTML tables in the page. If you want to create a page like this: This page has a top navigation bar, a left navigation bar, and a content area to the right. You can use a two-row, two-column large table to build it. In the first row, merge two columns, and then insert a top navigation bar. In the column to the left of the second row, insert a table to display the navigation buttons. In the right column, place a table for the actual content. (See figure I) The code generated by this nested table is this:

<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 the body of page--> </TD>
</TR>
</TABLE>

However, in fact, when a browser finds a <TABLE> label, it does not immediately display the page to the screen unless it finds the appropriate closing tag </TABLE>. So, if your entire page is in a table, nothing will be displayed until the last </TABLE> is received, so that the page will be visible to the user after the entire file has been downloaded. This feature can cause a temporary pause when the volume of page data is larger (such as search results for search engines). To prevent this from happening, you can divide the page into small tables when you make it. At the end of each HTML code that is <TABLE> to the appropriate </TABLE> section, the browser displays it. In the view of the visitor, the page is gradually, some part, more and more appear on the screen. Feeling, such a page display faster than downloading the entire file again.

By using this principle to study the previous example, you should divide the entire large table in the page into three separate tables. Use the first table to display the top navigation bar, adjust its width so that it holds all the content, and complete it in a <TABLE> </TABLE> code snippet. The bottom half of the page, and the second table on the left is lined with a column. Use a third table to accommodate the actual content. (see figure II) because each part is a complete table, each part of the code is immediately displayed when it is downloaded. This way, the top and left navigation bars will show more than the rest of the page. At this point the user imagines that the page will start downloading and will soon be displayed on the screen. This is much better than allowing the user to face a blank screen for a long time.

The modified code is like this:

<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 example above, we just close the <TABLE> tag earlier and make the page appear faster in the browser. And so on, there are some similar tags that have the same characteristics.

For example, create list boxes and combo boxes to <OPTION> mark and generate list items <LI> tags. Typically, an ASP programmer accesses the database and feeds the data into a list box or combo box created by <OPTION>, and then writes a close <OPTION> tag in the code, so that simple changes can also make the page appear faster in the browser.

Do not use such a code:

Do as Not objrs.eof
Stroptionlist = stroptionlist & "<option value=" "& objRS (" ID ") &_" ">" & _objrs ("ProductName")
Objrs.movenext
Loop

Response.Write "<select size=" "1" ">" & Stroptionlist & "</SELECT>"

To use this code:
Do as Not objrs.eof
Stroptionlist = stroptionlist & "<option value=" "& objRS (" ID ") & _" ">" & objRS ("ProductName") & "</OPTION>"
Objrs.movenext
Loop

Response.Write "<select size=" "1" ">" & Stroptionlist & "</SELECT>"

Do not use such a code:
<UL>
<LI> Apples
<LI> oranges
<LI> Bananas
</UL>

Use this code:
<UL>
<LI> Apples </LI>
<LI> oranges </LI>
<LI> Bananas </LI>
</UL>

Now look, does your page appear fast in the browser?

Please do not underestimate the importance of these changes to improve the performance of ASP programs. Perhaps, in a book or online material that you can find "tips and hints," there is little mention of optimizing HTML code to make your program run faster. However, in the actual application of these technologies, it is true that the program performance can be greatly improved.



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.