Skills
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 related sets, this is more than accessing
A local variable is much slower. 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:
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
Do not use the form of strpage=request ("page") to get the argument if it is not a choice, because it will search all the collections sequentially-
QueryString, Form, Cookies, ClientCertificate, servervarible until the name of the first matching value is found. This is more appropriate than direct access
The collection is inefficient and unsafe unless it is absolutely guaranteed that the value will not appear in another set.
For example, you might want to search for a Web server name that satisfies a customer request, which is found in the Request.servervarables collection in each query
"SERVER_NAME" to achieve. However, if the other collection also contains a value named "SERVER_NAME" (the key name is case-insensitive), use the request
("SERVER_NAME"), you get the wrong result. 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 stop downloading, we don't have to waste the server's resources creating pages because the buffer content will be discarded by IIS. So, for those who need a lot of time to compute or
Resources to use more pages, it is worth checking at each stage whether the visitors are offline:
...... 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
Typically, the data forms 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, naming each column individually gives the best sex
can, 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 the 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. Example:
While not rsgc.eof
Response.Write "Project name:" & RSGC ("GCMC") & "(Project Code:" & RSGC ("Gccode") & ")
Rsgc.movenext
Wend
can be rewritten to speed up execution with the following code:
Set GCMC=RSGC ("GCMC")
Set GCCODE=RSGC ("Gccode")
Whil E not rsgc.eof Response.Write "project name:" & GCMC & "(Project Code:" & Gccode & ")
" Rsgc.movenext
Wend
New The code establishes a reference to an object variable, so you can use an object variable instead of the actual variable, which means that the script engine's work is reduced because the number of indexes in the set
hop becomes less.
Tip Five: Don't mix script engines
We know that you can use either VBScript or JScript in an ASP page. But using both JScript and VBScript on the same page is not
Desirable. Because the server must instantiate and attempt to cache two (rather than one) scripting engines, this increases the system burden to some extent. Therefore, from the sexual
You should not mix multiple scripting engines on the same page to consider.