ASP Lecture 11: Conclusion - giving you some suggestions
Author:Eve Cole
Update Time:2009-05-30 19:54:51
1. Optimization of ASP pages and codes
1. Try to use the !--#include file directive instead of the framework structure.
One of the more popular design patterns in the past was to use a frame (Frame) to place the directory structure of the website and display the content in another frame. This design idea is essential, but it will affect the website performance. In terms of specific implementation, you can completely use the !--#include file directive to design a navigation bar. As for the use of include, examples have been given as early as in Lecture 1.
2. Try not to let visitors waste time waiting for nothing to change.
Do not use this method to process first and then output the processing results to the page. As a result, there will be no changes to the client page during the processing period. No matter how patient you are, you will feel extremely annoyed by this. You should try to process and output at the same time. In fact, the paging display technology we introduced in Lecture 8 is exactly the same. Here is another example.
Code 1 (process first and then display):
<table width="100">
<% while not rs.eof %>
<tr>
<td><%=rs(“name”)%></td>
<td><%=rs(“email”)%></td>
</tr>
<% rs.movenext
wend %>
</table>
Code 2 (display while processing, process one item and display one item):
<% while not rs.eof %>
<table width=”100” border=0>
<tr>
<td><%=rs(“name”)%></td>
<td><%=rs(“name”)%></td>
</tr>
</table>
<% rs.movenext
wend %>
3. Avoid using Session variables, especially between pages.
Using session variables will reduce efficiency because not only does a variable need to be created for each visitor, but the memory occupied by the session variable will not be released until 20 minutes after the visitor leaves (default Timeout setting).
4. Don't use databases blindly.
Beginners often use databases after they have some experience with databases. Firstly, they can review their past experience, and secondly, they can demonstrate their database technology. My suggestion is that it is best to use the database less when other methods can be used. Accessing the database always consumes server resources. For example, you can use text files. In addition, for some data that does not change much but is frequently used, you can use the Application object to store the data in array variables. Obtaining data from memory is much faster than from the database.
5. Use Option Explicit to force declaration of variables. This can improve the efficiency of ASP script execution and reduce the possibility of script errors. It should be a good habit.
6. Use local variables defined with Dim whenever possible. Accessing local variables is much faster than accessing global or undeclared variables.
7. It is best not to frequently intersect HTML code and ASP code, and try to connect ASP code or HTML code into one piece to improve the efficiency of script operation (this is similar to the principle of playing games).
If you write the output results in the <%=...%> format in several places in the code, then consider combining these results into one and writing them out using a Response.Write statement, such as the example wuf9 in Lecture 2 .asp. Don't spread HTML code and VBScript scripts too far apart, try to write HTML and VBScript scripts in chunks.
8. Use absolute paths appropriately. If possible, avoid using relative paths and use absolute paths. Using relative paths will require IIS to return the current server path, which means that special requests to IIS will cause slow execution. But having said that, it is a bit slow, but using relative paths can greatly enhance the flexibility and portability of the program. The key is to handle this contradiction appropriately.
9. ASP script performance testing You can use some tools to test the time it takes for your ASP script to execute, especially if you think there is a problem with the script. Here are a few provided. Please see the help for specific usage.
(1) Microsoft's InetMonitor tool: used to monitor and test the processing capabilities of the entire website. Download address: http://www.microsoft.com/siteserver/site/DeployAdmin/InetMonitor.htm.
(2) Microsoft's Web Capacity Analysis Tool (WCAT). It is included in the Microsoft BackOffice Resource Kit CD, or you can download it from the Microsoft website.
(3) Softwing's ASP Profiling Component, download address: http://www.softwing.com/iisdev/profiler/.
2. Optimization of database performance
1. Use a driver that binds the database directly to OLE DB, not through ODBC. Regarding this point, see Lecture 6 for details.
2. Try to use the system's default cursor (CursorType) and lock (LockType) types, especially avoid using dynamic cursors.
3. Use stored procedures appropriately. Stored procedures are more efficient than query strings, are much more convenient to use, and have many benefits.
4. Release resources in a timely manner, such as releasing objects as early as possible, closing connections, etc.
5. Database performance test (1) To test the speed of SQL queries, you can use Microsoft Isql/w (Microsoft SQL Server 6.5) or Microsoft Query Analyzer (Microsoft SQL Server 7.0), which can display each step of execution and the time required.
(2) Profiler of Microsoft SQL Server 7.0 can track and monitor queries executed on the database server. For example, you can track the slowest running queries or the queries that most often cause database deadlocks.
3. Several other questions
1. Other optional ASP development platforms. The ASP scripts we have talked about before were all created on Microsoft series platforms. In addition, you can also choose Chili!ASP to run ASP. Its outstanding advantage is that it can run on Windows NT and Unix platforms. All can be used. Home page address: http://www.chilisoft.com/.
2. About <% @language=VBScript%>
In all the ASP scripts we have encountered before, the first line of code at the beginning is basically <% @Language = VBScript%>, which indicates that the scripting language used by the ASP script on this page is VBScript. In fact, in ASP Other scripting languages such as Jscript and PerlScript can also be used.
In ASP, you can set the entire Web site to use one scripting language (such as VbScript, which is also the default setting of IIS), and use another scripting language (such as Jscript) for a specific page, or even use it for a specific page. A function on a page uses another scripting language. Let's give an example below:
(1) How to set the script language used by the entire Web site.
Run ISM (Internet Service Manager) → right-click the website name, select Properties → select the Home Directory tab → click the Configuration button → select the App Options tab in the Application Configuration dialog box → enter VbScript or Jscript in the Default ASP Language text box That’s it.
(2) Routine wuf99.asp
<% @Language = PerlScript %>
<Html>
<Head><Title>Bye</Title></Head>
<Body>
<%
$Response->write(
sprintf( "IP address = %s",
$Request->ServerVariables(
"REMOTE_ADDR" )->item ) );
%>
<SCRIPT LANGUAGE="JScript" RUNAT="Server">
function saybye()
{
Response.Write("Goodbye!")
}
</SCRIPT>
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
For I=1 to 3
saybye()
Next
</SCRIPT>
</Body>
</Html>
Note: You can freely use VBSript or Jscript in ASP, because Microsoft supports both (IE supports Netscape's JavaScript and develops it into Jscript, but NetScape does not support VBScript. This is probably because NetScape came first. One of the reasons why Microsoft is involved in lawsuits), but to use PerlScript, you must install an additional Perl scripting language environment. It is recommended to use ActivePerl. It is very convenient to install on Windows NT. Download address: http://www.newhua.com.cn/activeperl.htm.
3. A good ASP design example. There are many ASP examples on the Internet, mainly concentrated in guest books, chat rooms, news releases, BBS, etc. Here we recommend a BBS system designed with ASP - Free BBS. The download address is: http: //free_bbs.soim.net/.
At this point, the ASP lecture series is coming to an end, but there are still many issues that have not been covered, such as Windows 2000 and IIS5.0, ASP security issues, and other concepts related to IIS or NT (Windows DNA, MTS, MSMQ) Wait... If there is a chance, we can meet here again in the future. This time, goodbye!