Learn and implement vital tips on increasing your website’s
performance. Find out how to make
general improvements, how to optimize images, tweak HTML source code, get
better results from ASP and ASP.NET, tune your database, and enhance IIS.
Use one or more suggestions to give website visitors a
better impression and keep them on your site longer.
Sections
- General
- Images
- HTML
- ASP
- ASP.NET
- Database
- IIS
General – Hardware and Monitoring
- Host
your website with a company known for performance. Check newsgroups and web host listing
sites such as TopHosts (http://www.tophosts.com)
for companies known for high performance.
In a shared server environment (not dedicated hosting), find out
how many other websites are on the same server as yours. Some web hosts will put up to 1 thousand
sites on one server.
- When
hosting your own website, install as much physical RAM as possible on the
web server. As memory gets cheaper
and cheaper by the minute it is one of the most cost effective purchases
an IT department can make.
- When
hosting your own website, use quality hardware – don’t try and save money
when purchasing the hardware that will run one of your most valuable
assets.
- When
hosting your own website, consider purchasing quality NIC cards which can
offload and reduce CPU usage for networking.
- Monitor
your web pages for performance to make more informed decisions. End-to-end testing of your website, e.g.
testing of multiple web pages on your website, is essential to
understanding weak points and places for improvement. Use tools like WebWatchBot (http://www.exclamationsoft.com/webwatchbot/default.asp)
to measure performance and report on trends.
Images
- Reduce
the size of images by reducing the number of colors. Optimize your images with online tools
like GifWorks (http://www.gifworks.com).
- Reduce
the size of images by reducing its dimensions. Cropping images, also known as
relevance-enhancing, can reduce size and also help focus the attention of
the quick eye of the web surfer.
- Use
the jpg format for photos. Jpeg compression
is known for its exceptional compression abilities with regard to
photos. Many tools, such as ACDSee
(http://www.acdsee.com/) can easily
convert images from one format to another and allow you to set the
compression level for jpeg images.
- Reduce
the total number of images on one page.
Most web browsers download up to 4 images concurrently; however,
each connection adds to the overall response/load time.
- Reuse
images whenever possible to take advantage of server-side (web server) and
client-side (browser) caching.
- Specify
image WIDTH and HEIGHT attributes for faster loading in the browser.
- Combine
images and use image maps instead of segmenting images, remembering that
each image loaded is a connection between the web browser and the web
server.
- Use
image ALT attributes sparingly.
Each character adds to the size of the web page and to the load
time.
HTML
- Use
comments sparingly. While invisible
when a web page is loaded in a browser, the comments are still transferred
from the web server, needlessly wasting bandwidth.
- Avoid
unnecessary HTML tags: not all tags need a closing tag. For example, it is not necessary to have
a close </br> or </li> tag.
- Optimize
your HTML code with free online tools such as iWebTool (http://www.iwebtool.com/html_optimizer)
to reduce the overall size of the html file.
- Avoid
using frames. Each frame loads its
own web page which can increase the overall response time of a webpage.
- Minimize
the amount of text and sub-tags between the HEAD open and close tag.
- Place
external JavaScript tags, i.e. with src=”[someurl]”, at the end of the
document to delay loading.
- Simplify
tables and avoid nested tables (tables within tables).
- In
tables use background colors instead of images.
- Avoid
using WYSIWYG editors, e.g. FrontPage, that include extra and irrelevant
text and HTML tags. Learn to edit
HTML code by hand.
ASP
- Disable
Session State if not using sessions.
If you are using sessions, consider using cookies or an id in the
query string along with temporarily storing data in a database. To disable session state, at the top of
your ASP page, include the directive:
<%@ ENABLESESSIONSTATE=false %>
- Use
Option Explicit to reduce coding errors.
At the top of your ASP page, include the directive:
<% Option Explicit %>
- Use Server.Transfer
over Response.Redirect.
Response.Redirect uses an additional round-trip to the web server
whereas Server.Transfer does not, reducing the amount of bandwidth used,
system resources, and overall response time.
- When
specifying a URL without a web page, e.g. http://www.exclamationsoft.com,
include the trailing slash, e.g. http://www.exclamationsoft.com/, to save a trip back to the web server.
- Reduce
the use of global variables.
- Reduce
the number of include files used on a page. Also, segment and categorize functions
in commonly used include files.
- Be
careful of string concatenation as the size of the string grows. As the string grows through
concatenation, it is copied to a new location in memory each time.
- Set
objects, especially database objects to Nothing when no longer
needed. For example, Set oRecordset
= Nothing.
- Keep
blocks of ASP script together. Each
switch between ASP script and HTML causes the compiler to stop and start
processing.
- Don’t
use ASP commenting: <% ‘ comment %> which is compiled each time the
page is loaded. Instead, use HTML
commenting or no commenting at all.
- Don’t
leave empty Session_OnStart or Session_OnEnd methods. If Sessions are not used in your
application, remove these two methods since they will be compiled and
executed even when empty.
ASP.NET
- ASP.NET
Cache API. If you are not using the
Cache API, stop your coding and read the help on this subject and
implement it as soon as possible.
- Reduce
multiple database resultsets. Each
database query with returned results is a round trip to the database
server, adding to the overall response time.
- Use
“paged” data access, e.g. ASP.NET makes it easy to create DataGrids and
DataLists of results from database queries. Use them to your advantage by only
showing a small sub-set of those results to improve web page response
times.
- Use HttpContext.Items
to add frequently used objects during a single page load to create a
“per-request” cache.
- Utilize
background processing to help with long running tasks. Create multi-threaded operations when
possible and feasible.
- Use
quick page caching for pages that are displayed repeatedly (think
auto-refresh):
<%@ Page OutputCache VaryByParams="none"
Duration="60" %>
- If not
using form post-back, turn off viewstate:
<%@ Page EnableViewState="false" %>
- Avoid catching
unnecessary exceptions: exceptions incur a large amount of overhead and
should not be used for program logic flow control.
- Avoid
throwing exceptions.
- Enable
buffering.
- Use
Page.IsPostBack to prevent code from being needlessly executed.
- Ensure
debug is set to false and the release build is used in production.
- Use
client-side validation controls to reduce server round-trips.
- Use
StringBuilder when concatenating strings.
Database
- Use
SQL Server or another professional level database over Access.
- Use
stored procedures over simple SQL queries.
- Connection
Pooling – ensure connection pooling is enabled by using a DSN (Data Source
Name) in the ODBC Data Source Administrator.
IIS
- Use
server side compression software such as Port80’s httpZip (http://www.port80software.com/products/httpzip/)
- Use
GZip compression to reduce bandwidth, but be aware that CPU utilization
may go up. A-B testing can help you
find the right balance of whether GZip compression is right for your
website.
- Use
IIS 6.0, which includes significant performance enhancements such as
Kernel Caching.
- Don’t
install or use Microsoft Index Server unless you need it. The cost far outweighs the benefits that
Index Server will give.
- Don’t
enable logging unless needed.
Logging is disk and resource intensive.
- Run
IIS “in-process” if the website is mostly static. Mostly dynamic or unstable websites
should not use this setting.
- Enable
“Cache ISAPI applications” for sites that use ASP which benefits greatly
from this setting.
- Disable
debugging on production servers.
- Enable
“HTTP Keep Alives” for IIS 5.0 – This setting is enabled by default in IIS
6.0.
- Shorten
connection timeouts to reduce the hold on resources.
Resources used:
1.
MSDN
2.
Chapter
6 — Improving ASP.NET Performance
3.
Tips to Improve ASP
Application Performance
4.
IIS 101:
The Basics of Performance Tuning
5.
Top
Ten Ways To Pump Up IIS Performance
|