ASP can be used to create dynamic interactive web pages and build powerful web applications, but ASP collections are time-consuming and consuming computing resources. So how should we speed up? Now let’s take a look at the ASP speedup skills.
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:
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 IfTips 2: Direct access to the appropriate collection
If not, don't use strPage=Request("page") to get the parameters, because this will search all the collections QueryString, Form, Cookies, ClientCertificate, ServerVarible in order until the name of the first matching value 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:
... 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:
While Not RsGc.EOF Response.Write "Project name: " & RsGc("GcMC") & "(Project code: " & RsGc("GcCode") & ")" RsGc.MoveNext WendYou can use rewritten as follows 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 WendThe 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 are the five tips for speeding up ASP. We can learn these five tips to speed up the website opening. If you want to know more, please follow the Wrong New Technology Channel.