Accessing ASP collections to obtain ASP is a time-consuming and computer resource-consuming process. Because this operation includes searching for related collections, it will be much slower when accessing local variables. Let's now see how to improve ASP efficiency.
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 are required. 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.
b. Use stored procedures as much as possible. Stored procedures are pre-compiled programs that contain a ready execution plan, so they execute faster than SQL statements.
c. Use the appropriate cursor and lock mode. If all the work is done is to read data from the record set and display it on the screen, then the default forward-only, read-only record set is used. The less work ADO uses to maintain the details of records and locking, the higher the performance of execution.
d. Use object variables. A sure way to improve performance when traversing a record set is to use object variables to point to members in the set. For example:
The code copy is as follows:While Not RsGc.EOF
Response.Write "Project name: " & RsGc("GcMC") & "(Project code: " & RsGc("GcCode") & ") "
RsGc.MoveNext
Wend
You can use rewritten as follows to speed up execution:
The code copy is 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 creates references to object variables, so object variables can be used instead of actual variables, which means the script engine works less because the number of indexes in the set becomes less.
Tips 5: Don't mix script engines
We know that you can use both VBScript and JScript in ASP pages. However, it is not advisable to use both JScript and VBScript on the same page. Because the server has to instantiate and try to cache two (not one) script engines, this adds to the system burden to some extent. Therefore, from a performance perspective, multiple scripting engines should not be mixed in the same page.
The above is all the content of this article. I hope it will be helpful to everyone's learning, and I hope everyone will support the wrong new technology channel.