When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Sunday, December 13, 1998

WebDaily: Your daily source for Web Technology Tips and Tricks!

Increasing the Speed of your ASP Scripts

* This article describes techniques you can employ to speed up the execution time of your ASP scripts.

Web surfers are impatient people. If a page takes too long to load, a surfer will probably just shoot off to another URL. This is one reason why ASP scripts should be optimized for speed. Another more important reason, is that when you have multiple people hitting your server, the less time it takes to server one ASP file the better, so you are not overburdening the webserver.

One way to increase the performance of your ASP web page is to set @ENABLESESSIONSTATE to False. If a certain ASP page does not use any Session variables, be sure to add the following line to the top of the ASP page:


Another tip for increasing speed performance is if you are using a particular item from a particular collection often (like Request.ServerVariables), copy the value to a local variable rather than accessing the collection each time you need the information. Suppose you were using the LOGON_USER variable in the Request.ServerVariables collection four or five times on one page. Rather than referring to it as Request.ServerVariables("LOGON_USER") each and ever time, it would be more efficient to do the following:

LOGON_USER = Request.ServerVariables("LOGON_USER")

and then refer to it as LOGON_USER everwhere you had previously referred to it as Request.ServerVariables("LOGON_USER"). The reason behind this is because it is quicker to access a local variable than to have to perform lookup processing in the collection for each and every reference.

As always, be sure NOT to put large objects in the Session. Putting an ADO object in the Session, or some large business object, is only asking for trouble. Since an instance of that object will be created for each user who hits your site, and since that object will persist for (most likely) 20 minutes AFTER the user leaves your site, putting large objects in Session level variables puts a TREMENDOUS amount of overhead on your server and gobbles up memory very quickly! (For Pros & Cons of Session variables, visit this article.)

Avoid redimming arrays. According to Microsoft, it is quicker to just create a new, larger array than to redim an old one. Redimming arrays, in my opinion, shows a flaw in software design. An application should be created where dynamic arrays are not needed. Often times developers turn to dynamic arrays because they are easy to implement using VB / ASP. While they are easy to use, they are not very performance-savy.

Another good tip is to use client-side form validation where possible rather than server side. When a user enters data into a form, developers can write client-side JavaScript to make sure the user has entered valid data into the various INPUT boxes. Another approach is to have an ASP file check the fields before inserting them into the database. If the fields are invalid, the user is redirected to the FORM page, requested to adjust the offending fields. This latter process requires a round trip to the server to determine if the fields are valid or not. With client-side validation, once they submit the form, the data can be checked instantaneously. To learn more about JavaScript and client-side validation, visit this article.

To increase the performance of your database calls on your ASP page, be sure that your webserver has connection pooling is turned on. To determine if your server is using connection pooling, refer to this article.

As you have hopefully seen, you can increase the performance of your ASP scripts in a number of ways. By applying the above suggestions to your ASP scripts, you and your web visitors will note an increase in speed.

Happy Programming!

To subscribe to WebDaily, point your browser to:

Please forward this information to a friend, including the subscription URL! Happy Programming!

Related Articles
  • Optimizing your ASP Code
  • Speeding up your ASP Scripts
  • Using ADO 2.0's GetString to Speed up your ASP Scripts
  • How to Use Connection Pooling to Speed up your Queries

    ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article