ASP page to improve the speed of access to the method of detailed application techniques _

Source: Internet
Author: User

One technique: Improving the efficiency of using the request collection

Accessing an ASP collection to extract a value is a time-consuming process that takes up computational resources. Because this operation contains a series of searches for the related set, this is much slower than accessing a local variable. Therefore, if you intend to use a value in the request collection more than once in a page, you should consider storing it as a local variable.
For example, write your code in the following form to speed up script engine processing:

Copy Code code as follows:

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 Two: Direct access to the appropriate set

If you don't have a choice, do not use the form of strpage=request ("page") to get the arguments, as this will search all collections in order-querystring, Form, Cookies, ClientCertificate, Servervarible until the name of the first matching value is found. This is less efficient than direct access to the appropriate set, and is unsafe unless it is absolutely guaranteed that the value does not appear in another set.
For example, you might want to search for a Web server name that satisfies a customer request, which is done by looking for "server_name" in the Request.servervarables collection in each query. However, if the other collection also contains a value named "SERVER_NAME" (the key name is case-insensitive), you will get the wrong result when you use Request ("SERVER_NAME"). In summary, you should access the appropriate collection as direct as possible.


Tip Three: Use the Response.IsClientConnected property before a time-consuming operation

Using response.isclientconnected is a useful way to observe whether a user is still connected to the server and is loading the Web page created by ASP. If the user disconnects or stops downloading, we don't have to waste the server's resources creating the page because the buffer content will be discarded by IIS. Therefore, for those pages that require a lot of time to compute or use more resources, it is worth checking that the viewers are offline at each stage:

Copy Code code as follows:

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

Tip Four: Optimizing ADO operations in ASP

Generally speaking, the data constitutes the actual content of the Web site. Therefore, it is useful to optimize ADO operations to speed up ASP code execution:

A. Select only the columns you want: When you open an ADO recordset, you should not automatically use the table name (that is, select *) unless you need to get all the columns. Using a separate column means that the amount of data sent to or removed from the server will be reduced. Even if you need to use all the columns, it is best to name each column individually, because the server does not have to explain the names of these columns.

B. Use stored procedures as much as possible. A stored procedure is a precompiled program that contains a prepared execution plan, so it executes faster than the SQL statement.

C. Use the appropriate cursor and lock mode. If all you do is read data from the recordset and display it on the screen, use the default only forward, read-only recordset. The less work ADO uses to maintain the details of records and locks, the higher the performance of the execution.

D. Use object variables. One way to definitely raise performance when traversing a recordset is to use object variables to point to members in the collection. For example:

Copy Code code as follows:

While not rsgc.eof
Response.Write "Project name:" & RSGC ("GCMC") & "(Project Code:" & RSGC ("Gccode") & ")"
Rsgc.movenext
Wend

You can use the code rewritten as follows to speed up execution:

Copy Code code as follows:

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 establishes a reference to an object variable, so you can use object variables instead of actual variables, which means that the script engine has less work because the number of indexes in the collection has become smaller.

Tip Five: Don't mix script engines

We know that you can use either VBScript or JScript in an ASP page. However, it is not advisable to use both JScript and VBScript on the same page. Because the server must instantiate and attempt to cache two (rather than one) scripting engines, this increases the system burden to some extent. Therefore, for performance reasons, you should not mix multiple scripting engines on the same page.

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.