25+ ASP tips for improving performance and styling

Source: Internet
Author: User
Tags array arrays functions iis include object model variables variable
Skills | performance
25+ ASP tips for improving performance and styling

--------------------------------------------------------------------------------
Len Cardinal-microsoft Consulting Services Senior Advisor
George v. Reilly-microsoft, IIS performance supervisor
Update Time: April 2000
According to Nancy Cluts's article (English) rewrite
Nancy Cluts-Developer technical engineer
Microsoft Corporation

Summary: This article provides tips for optimizing ASP applications and VBScript.

Directory

Brief introduction

Tip 1: Caching common data on a WEB server

Tip 2: Cache commonly used data in application or session objects

Tip 3: Caching Data and HTML on a WEB server disk

Tip 4: Avoid caching inflexible components in application or Session objects

Tip 5: Do not cache a database connection in a application or Session object

Tip 6: Magical Session Objects

Tip 7: Encapsulate code in a COM object

Tip 8: Get resources later and release resources early

Tip 9: Out-of-process execution will sacrifice reliability

Tip 10: Explicit Use options

Tip 11: Use local variables in subroutines and functions

Tip 12: Copy common data to a script variable

Tip 13: Avoid redefining arrays

Tip 14: Use response buffering

Tip 15: Batch inline scripts and Response.Write statements

Tip 16: Use response.isclientconnected before you start a long task

Tip 17: Instantiate objects with <OBJECT> tags

Tip 18: Use the TypeLib binding of ADO objects and other components

Tip 19: Leverage your browser's ability to authenticate

Tip 20: Avoid string concatenation in loops

Tip 21: Enable browser and proxy caching

Tip 22: Use Server.Transfer instead of Response.Redirect whenever possible

Tip 23: Add a slash at the end of the directory URL

Tip 24: Avoid using server variables

Tip 25: Upgrade to the latest and best version

Tip 26: Adjust your WEB server

Tip 27: Perform a performance test

Tip 28: Read Resource Links


--------------------------------------------------------------------------------

Brief introduction

Performance is an attribute. You need to design your performance in advance, or rewrite your application later. In other words, what is a good strategy for maximizing the performance of Active Server Pages (ASP) applications?

This article provides a number of tips for optimizing ASP applications and the Visual Basic (R) Script Editor (VBScript). Many pitfalls and flaws were discussed. The recommendations listed in this article have been tested on http://www.microsoft.com and other sites and are working properly. This article assumes that you have a basic understanding of ASP development, including for VBScript and/or JScript, ASP application, ASP sessions, and other ASP internal objects (requests, responses, and servers).

ASP's performance, usually depends not only on the ASP code itself. We do not want to include all the wisdom in an article, but only at the end of the list of resources related to performance. These links include ASP and non-ASP topics, including ActiveX (R) Data Objects (ADO), part object Model (COM), databases, and Internet Information Server (IIS) configurations. These are our favorite links-be aware of them.

Tip 1: Caching common data on a WEB server

A typical ASP page retrieves data from the back-end database and then converts the result to Hypertext Markup Language (HTML). Retrieving data from memory is much faster than retrieving data from a back-end database, regardless of the speed of the database. Reading data from a local hard disk is often much faster than retrieving data from a database. As a result, you can often improve performance by caching data on a WEB server (in memory or disk).

Caching is a typical tradeoff between space and time. If you cache the data appropriately, you will see a dramatic improvement in performance. To make the cache work, it must maintain data that is frequently reused, and the cost of recalculation of the data is expensive or more expensive. If the cache is full of garbage data, it is a waste of memory.

Data that is infrequently changed is also a cached candidate because you do not have to worry about synchronizing data with the database. combo boxes, reference tables, DHTML fragments, Extensible Markup Language (XML) strings, menu items, and site configuration variables, including data source names (DSNs), Internet Protocol (IP) addresses, and Web paths) are cached candidate data. Note that you can cache the representation of the data rather than the data itself. If ASP pages do not change frequently and the cost of caching is very high (for example, the entire product catalog), consider generating HTML beforehand, rather than redrawing each request.

Where should the data be cached, and what caching policies are there? Data is often cached on Web server memory or on a Web server disk. The following two tips discuss these options.

Tip 2: Cache commonly used data in application or session objects

ASP Application and Session objects provide a convenient container for caching data in memory. You can either give the data to the Application object or assign the data to the session object, which will remain in memory in the HTTP call. Session data is stored by user, and application data is shared among all users.

When will data be loaded into application or session? Typically, the data is loaded when the application or session is started. To load data at application or session startup, add the appropriate code in the following two functions: Application_OnStart () or Session_OnStart (). These two functions should be in Global.asa, and if not, you can add these functions. You can also load data the first time you need it. To do this, add some code (or write reusable script functions) to the ASP page that checks for the existence of the data and loads the data when it does not exist. This is an example of a classical energy technique called lazy Computing-no calculation before you really need it. Take a look at the example:

<%
Function getemploymentstatuslist
Dim D
D = Application ("Employmentstatuslist")
If d = "" Then
' Fetchemploymentstatuslist function (not shown)
' Fetch data from DB, return array
D = fetchemploymentstatuslist ()
Application ("employmentstatuslist") = d
End If
Getemploymentstatuslist = d
End Function
%>

You can write similar functions for each piece of data that you want.

What format should the data be stored in? Any variable type can be stored, because all script variables are different. For example, you can store strings, integers, or arrays. Typically, you will store the contents of an ADO recordset as one of these variable types. To get data derived from an ADO recordset, you can manually copy the data into a VBScript variable, one field at a time. Using an ADO recordset to preserve Functions GetRows (), GetString (), or Save () (ADO 2.5) is faster and easier. The full and detailed content is beyond the scope of this article. The following demo function uses GetRows () to return an array of recordset data:

' Fetch Recordset, return with array
Function fetchemploymentstatuslist
Dim RS
Set rs = CreateObject ("ADODB.") Recordset ")
Rs. Open "Select Statusname, Statusid from Employeestatus", _
"Dsn=employees;uid=sa;pwd=;"
Fetchemploymentstatuslist = Rs. GetRows () ' Returns data as an array
Rs. Close
Set rs = Nothing
End Function

Further improvements to the above example should be to cache the HTML of the list, rather than caching the array. The following is a simple example:

' Take the recordset and return it in the HTML options list
Function fetchemploymentstatuslist
Dim RS, Fldname, S
Set rs = CreateObject ("ADODB.") Recordset ")
Rs. Open "Select Statusname, Statusid from Employeestatus", _
"Dsn=employees;uid=sa;pwd=;"
s = "<select name=" "Employment



Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.