One of the tips: Improve the efficiency of using Request collections
Accessing an ASP collection to extract a value is a time-consuming and computing resource consuming process. Because this operation contains a series of searches for related sets, this is much slower than accessing a local variable. Therefore, if you intend to use a value from the Request collection multiple times in the page, you should consider storing it as a local variable.
For example, write the code into the following form to speed up the script engine processing:
The code copy is 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
Tips 2: Direct access to the appropriate collection
If not, don't use strPage=Request("page") to get parameters, because this will search all collections in order—QueryString, Form, Cookies, ClientCertificate, ServerVarible until the first matching value name is found. This is less efficient than directly accessing the appropriate set and is unsafe unless it is absolutely guaranteed that this value will not appear in another set.
For example, it may be desirable to search for the WEB server name that satisfies the client's request, which is accomplished by looking for "SERVER_NAME" in the Request.ServerVarables collection that appears in each query. However, if other sets also contain values named "SERVER_NAME" (key names are case-insensitive), when using Request("server_Name"), an incorrect result will be obtained. In short, the appropriate collection should be accessed directly as much as possible.
Tips 3: Use the Response.IsClientConnected property before time-consuming operation
Using Response.IsClientConnected is a useful way to observe whether the user is still connected to the server and is loading the web page created by the ASP. If the user disconnects or stops downloading, we no longer need to waste the server's resources to create web pages, because the buffer content will be discarded by IIS. So, for web pages that require a lot of time to calculate or use more resources, it is worth checking at each stage whether the visitor is offline:
The code copy is as follows:
... 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
Tips 4: Optimize ADO operations in ASP
Generally speaking, data constitutes the actual content of the WEB site. Therefore, it is very useful to optimize ADO operations to speed up ASP code execution:
a. Select only the columns you want: When opening the ADO record set, the table name (i.e., SELECT*) should not be automatically used unless all columns need to be obtained. Using a separate column means that the amount of data sent to or fetched from the server will be reduced. Even if you need to use all columns, naming each column individually will achieve the best performance, because the server no longer has to interpret the names of those columns.