ASP acceleration skills

Source: Internet
Author: User

Tip 1: Improve the efficiency of using the request set
Accessing an ASP set to extract a value is a time-consuming and computing resource-consuming process. This operation contains a series of searches for related sets, which is similar
A local variable is much slower. Therefore, if you want to use a value in the request set multiple times on the page, you should consider storing it as a local variable.
For example, you can write the code below to speed up the processing of the script engine:

Strtitle = request. Form ("title ")
Strfirstname = request. Form ("firstname ")
Strlastname = request. Form ("lastname ")
If Len (strtitle) Then strtitle = strtitle &""
If strfirstname = "" Then strfullname = strtitle & "" & strlastname
Elseif Len (strfirstname) = 1 then
Strfullname = strtitle & strfirstname & "." & strlastname
Else
Strfullname = strtitle & strfirstname & "" & strlastname
End if
 

Tip 2: directly access the appropriate set
If there is no choice, otherwise do not use strpage = request ("page") to obtain parameters, because this will search all sets in order-
Querystring, form, cookies, clientcertificate, and servervarible until the first matching value is found. This is more suitable than direct access
When the set is inefficient and insecure, unless it is absolutely guaranteed that this value will not appear in another set.
For example, you may want to search for the Web server name that meets the customer's request, which is found in the request. servervarables set in each query.
"SERVER_NAME. However, if other sets contain a value named "SERVER_NAME" (key names are case-insensitive ),
("SERVER_NAME. All in all, access the appropriate set as directly as possible.

Tip 3: Use the response. isclientconnected Attribute before time-consuming operations
Using response. isclientconnected is a useful way to check whether the user is still connected to the server and loading the web page created by ASP. If the user disconnects
Or stop the download, So we no longer need to waste server resources to create webpages, because the buffer content will be discarded by IIS. Therefore
For webpages with many resources, it is worthwhile to check whether the visitors are offline at each stage:

...... Code to create first part of the page
If response. isclientconnected then
Response. Flush
Else
Response. End
End if
...... Code to create next part of page

Tip 4: optimize ADO operations in ASP
Generally, data constitutes the actual content of a web site. Therefore, it is very useful to optimize ADO operations to accelerate ASP code execution:
A. select only the required columns: When opening the ADO record set, the table name (select *) should not be used automatically unless all columns are obtained *). Use separately
This means that the amount of data sent to or from the server is reduced. Even if you need to use all the columns, naming each column individually will also achieve the best performance.
Yes, because the server does not need to explain the names of these columns.
B. Use stored procedures as much as possible. Stored procedures are pre-compiled programs that contain a prepared execution plan, so they are faster than SQL statements.
C. Use the appropriate cursor and lock mode. If all the work is to read data from the record set and display it on the screen, the default
Only records can be moved forward and read-only. The less detailed ADO is to maintain records and locks, the higher the execution performance.
D. Use object variables. When traversing a record set, one way to improve performance is to use object variables to point to Members in the set. For example:

While not rsgc. EOF
Response. Write "Project name:" & rsgc ("GCMC") & "(project code:" & rsgc ("gccode ")&")
"
Rsgc. movenext
Wend

You can rewrite the following code to speed up execution:

Set GCMC = rsgc ("GCMC ")
Set gccode = rsgc ("gccode ")
While not rsgc. EOF response. Write "Project name:" & GCMC & "(project code:" & gccode &")
"Rsgc. movenext
Wend

The new Code creates an object variable reference, so you can use the object variable instead of the actual variable, which means that the script engine's work is reduced because
The number of times of indexing is reduced.

Tip 5: Do not mix script Engines
We know that you can use VBscript or JScript on the ASP page. However, when JScript and VBScript are used on the same page
Optional. Because the server must instantiate and try to cache two (rather than one) script engines, which increases the burden on the system to a certain extent. Therefore, slave
You should not mix multiple script engines on the same page.

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.