This is the second post in my 'ASP Performance Best Practices' series. Read the first post about using ADO GetRows() here.
General ASP script tips:
Always buffer scripts. Are you still using Windows NT then turn on buffering in IIS - or enable buffering in each script by using: response.buffer = true. This is not needed in Windows 2000/2003 because buffering is enabled by default.
Always use Option Explicit.
Don't put objects in the application and session scope - unless you know what you are doing and that it is the best solution.
minimize session variables. Consider alternatives such as cookies, store in database, save to harddisk.
Don't mix scripting languages.
Don't mix ASP and HTML. If you need to then include HTML in response.write's.
Keep files as small as possible. This means: Learn to code proper HTML using W3C standards. Use CSS classes, no inline styles.
Re-use code. Put common functions in global include files.
Use COM objects instead of ASP whenever possible.
Instead of normal ASP scripts use VBScript classes (if you can't use COM objects).
Don't request the same values over and over again. Example:
if dbrs.fields("Drink").value = "Milk" Then Accept(false) elseif dbrs.fields("Drink").value = "Water" Then SaveForLater() elseif dbrs.fields("Drink").value = "Wine" Then CheckWineLabel() elseif dbrs.fields("Drink").value = "Beer" Then do until drunk Drink() GetNewBeer() loop else response.write "Unknown liquid" end if
Dim value value = dbrs.fields("Drink").value If value = "Milk" Then .....
querystring_value = request("var1") recordset_value = dbrs("Fieldname")
querystring_value = request.querystring.item("var1") recordset_value = dbrs.fields.item("Fieldname").value
In some cases there will be a default property, but if not then ASP has to loop through all possible properties to find what you are looking for. In the case of the Request object, ASP has to loop through the form, querystring, cookies, clientCertificate and serverVariables collections to find the variable. With ADO Recordset I am not sure if this is relevant, I think the fields collection is the default and the property collection is ignored - but I don't know.
Keep your code structured.
Comment your code.