1. Declare VBScript variables
In ASP, VBScript is provided with strong support and can seamlessly integrate VBScript functions and methods, which provides great convenience for extending the existing functions of ASP. Since the concept of variable types has been blurred in ASP, many programmers are accustomed to not declaring VBScript variables during the interaction between ASP and VBScript, which increases the parsing burden of the server and thus affects the server's response request speed.
In view of this, we can force the user to perform variable declarations in VBScript just as we force the user to perform variable declarations in VB. The implementation method is:
Place <% option explicit%> at the beginning of the ASP program line.
2. Encode the URL address
When we use ASP to dynamically generate a URL address with parameters and jump, it is normal to parse in IE, but there are errors when browsing NetScrape:
HTTP Error 400
400 Bad Request
Due to malformed syntax, the request could not be understood by the server.
The client should not repeat the request without modifications.
The solution is to use the URLencode method of ASP built-in server object to URL encoding the generated URL parameters. The example is as follows:
<%
URL="xur.asp"
var1="username=" & server.URLencode("xur")
var2="&company=" & server.URLencode("xurstudio")
var3="&phone=" & server.URLencode("021-53854336-186")
response.redirect URL & "?" & var1 & var2 & var3
%>
3. Clear the object
After using the object, first use the Close method to free up the system resources occupied by the object; then set the object value to "nothing" to free up the object's memory. The following code uses the database content to create a drop-down list. The code example is as follows:
<% myDSN="DSN=xur;uid=xur;pwd=xur"
mySQL="select * from authors where AU_ID<100"
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
if rstemp.eof then
response.write "Database is empty"
response.write mySQL
conntemp.close
set conntemp=nothing
response.end
end if%>
<%do until rstemp.eof %>
<%
rstemp.movenext
loop
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
4. Create SQL query using strings
Using strings to establish queries does not speed up the server's parsing speed. On the contrary, it will also increase the server's parsing time. But it is still recommended to use strings instead of simple query statements to query. The advantage of this is that it can quickly discover the problem of the program, thereby facilitating and efficiently generating the program. Examples are as follows:
<%mySQL= ""select * "
mySQL= mySQL & "from publishers"
mySQL= mySQL & "where state='NY'"
response.write mySQL
set rstemp=conntemp.execute(mySQL)
rstemp.close
set rstemp=nothing
%>
5. Use case for conditional selection
When making conditional selection, try to use case statements and avoid using if statements. Using case statements can make the program flowable and execute faster than if statements. Examples are as follows:
<%
FOR i = 1 TO 1000
n = i
Response.Write AddSuffix(n) & "<br>"
NEXT
%>