Optimization of ASP page and code
1. Try to replace the frame structure with!--#include file directives.
One of the more popular design patterns is to use a frame to place the directory structure of the site, in another frame to display content, such a design idea is essential, but it will affect the performance of the site. In the implementation of the way, the!--#include file instructions can be used to design a navigation bar, as for the use of include, as early as in the lecture on the example has been illustrated.
2. Try not to let the visitors pass the time without any change in the waiting.
Do not use such a way, first processing, and then output the processing results to the page, resulting in the processing of the time, the client page has not changed. A person with patience will also feel extremely annoyed, should try to use edge processing, edge output way. In fact, the paging display technology that we introduced in lecture eight Is this truth, and here's another example.
Code one (shown after processing):
<table width= ">"
<% While not rs.eof%>
<tr>
<td><%=rs ("name")%></td>
<td><%=rs ("email")%></td>
</tr>
<% Rs.movenext
Wend%>
</table>
Code two (side processing side display, processing one, displaying a):
<% While not rs.eof%>
<table width= "Border=0>"
<tr>
<td><%=rs ("name")%></td>
<td><%=rs ("name")%></td>
</tr>
</table>
<% Rs.movenext
Wend%>
3. Avoid using session variables, especially when using session variables between pages.
Using session variables can be inefficient because not only do you need to create a variable for each visitor, but the memory of the session variable is freed until the visitor leaves 20 minutes (the default timeout setting).
4. Do not blindly use the database.
Beginners often have experience with the database, use the database, one can warm, and then show their own database technology. My suggestion is that you should use the database less when you have other methods, and you will always consume server resources to access the database. For example, you can use a text file, in addition, for some infrequently changed and frequently used data, you can use the Application object to store the data in an array variable, from memory to get the data 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 likelihood of scripting errors, and should develop a good habit.
6. Use local variables defined with dim whenever possible. It is much faster to access a local variable than to access a global variable or a variable that is not declared.
7. HTML code and ASP code is best not to cross frequently, try to make ASP code or HTML code into a piece, to improve the efficiency of the script (which is similar to the reason for playing the game).
If you are writing the output in a <%=...%> format in several places in your code, consider bringing the results together and writing them in a Response.Write statement, as in Lecture II, example wuf9.asp. Do not spread HTML code and VBScript scripts too far, and try to write chunks of HTML and VBScript scripts.
8. Use absolute path appropriately
If possible, avoid using relative paths, and use absolute paths. Using a relative path will require IIS to return to the current server path, which means that the special requests for IIS cause low execution speed. But then again, slow is a bit slow, but using relative paths can greatly enhance the flexibility and portability of the program, the key is to properly deal with this contradiction.
9. ASP Script Performance test
You can use some tool software to test your ASP script execution time, especially if you feel the script is problematic. Here are a few, please see Help for specific usage.
(1) Microsoft's InetMonitor tool: Used to monitor and test the processing capabilities of the entire site. Download Address: http://www.microsoft.com/siteserver/site/DeployAdmin/InetMonitor.htm.
(2) Microsoft Web Capacity analysistool (WCAT). Included in the Microsoft BackOffice Resource Kit CD, or you can go to the Microsoft Web site to download it.
(3) softwing asp Profiling Component, download address: http://www.softwing.com/iisdev/profiler/.
II. Optimization of database performance
1. Use a driver that binds the database directly to OLE DB, rather than through ODBC. For this, please refer to lecture six.
2. Use the system default cursor (CursorType) and lock (LockType) types as much as possible, especially to avoid using dynamic cursors.
3. Use stored procedures appropriately. Stored procedures are more efficient than query strings and are much more convenient to use and have a lot of benefits.
4. Release resources in a timely manner, such as releasing objects as early as possible, shutting down connections, and so on.
5. Database Performance Testing
(1) To test the speed of SQL queries, you can use Microsoft ISQL/W (Microsoft SQL Server6.5) or Microsoft Query Analyzer (Microsoft SQL Server7.0), which shows each step of execution and the time it takes to do so.
(2) The profiler of Microsoft SQL Server7.0, which can track the monitoring of queries performed on the database server. For example, you can track records that run the slowest query or that most often causes a database to deadlock.
Third, several other issues
1. Other optional ASP development platform
The ASP scripts we talked about earlier were created on the Microsoft series platform, and you can choose chili! ASP to run ASP, its outstanding advantage is in both Windows NT and UNIX platform can be used. Home Address: http://www.chilisoft.com/.
2. About <% @language =vbscript%>
All the ASP scripts we've encountered before, the first line of code is basically <% @Language = Vbscript%>, which indicates that the scripting language used for this page's ASP script is VBScript, and in fact, you can also use JScript in ASP, PerlScript and other scripting languages.
In ASP, you can set the entire Web site to use a scripting language (such as VBScript, which is also the default for IIS), and use another scripting language (such as JScript) for a particular page, or even a different scripting language for one function of a page. Here's an example:
(1) How to set the scripting language used throughout the Web site.
Run ISM (Internet Service Manager) → Right-click the site name, select properties→ Select Home Directory tab → Click configuration button → select application The App Options tab in the configuration dialog box → Enter VBScript or JScript in the default ASP language text box.
(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= "VBScript" runat= "Server" >
For I=1 to 3
Saybye ()
Next
</SCRIPT>
</Body>
</Html>
Note: You can use Vbsript or JScript freely in the ASP, because Microsoft supports both (ie, Netscape's JavaScript and the development of JScript), while Netscape does not support VBScript. This may also be one of the reasons why Netscape first got to the Microsoft lawsuit, but to use PerlScript, you must install a different Perl scripting locale. Recommended use of ActivePerl, installed on Windows NT very convenient, download address: http://www.newhua.com.cn/activeperl.htm.
3. A good example of ASP design
There are many examples of ASP, mainly concentrated in the message, chat room, news release and BBS, here to recommend an ASP Design BBS system--free BBS, download the address: http://free_bbs.soim.net/.
Here, the ASP lectures are coming to an close, but there are still a lot of issues that are not covered, such as Windows2000 and IIS5.0, ASP security issues, and other concepts related to IIS or NT (Windows DNA, MTS, MSMQ), and so on ... if there is a chance , we can meet here again, this time, goodbye
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service