Want a faster website?  Studies show that slow websites can drive traffic away from your website and directly to your competitors. Performance tweaks are available for every application in varying degrees of ROI. Fortunately, there is an easy way to improve the speed of your ASP.NET website in just 4 lines of code.

A Faster Website

According to Yahoo's 13 Simple Rules for Speeding Up Your Website two of the most important changes you can make to your site are “Gzip Components” and “Add an Expires Header”. While there are numerous changes you can make, these two are the low hanging fruit targeted by the code outlined below.

The urlCompression element will allow IIS to perform Gzip compression of your static components. This is a feature supported by all popular web browsers and allows the web server to send HTML, CSS, and JavaScript content to a web browser in zipped format. The browser will then automatically unzip the file before trying to read the content resulting in reduced bandwidth usage at the cost of a little CPU load involved with doing the compression.
The second block “staticContent” enables the “Expires Headers”. This feature allows you to reduce bandwidth usage by informing web browsers that the content they previously requested is safe to hang on to and will not be changing in the near future. A good example of this is the CSS file associated with your site. The less frequently your CSS changes the more often you want visitors to reuse the CSS file they received from their last visit. There are a couple options to explore. This example uses a set date, of 3/29/2020, the other option is to use a max age configuration which tells the browser to keep the file for a number of days instead of a hard-coded fixed date in the future.

What Does It All Mean?

The caveat to this benefit is that the web browser will not find any changes made to this content until the expiration date has been reached. There are two good ways to address this. If you absolutely need your visitors to see a change today then use a new file name. The new name will not be found in the web browser cache and will be immediately downloaded. The second option is to use a shorter duration cache. This will still reduce the bandwidth load for your application but will ensure that visitors receive the changes in a timely manner.

Both of these configurations should be placed inside of the system.webServer element of the web.config file. Before you give it a try remember this.  Using this configuration enables IIS7 features.  As a result, you will not improve the performance of your website hosted in Cassini Server through Visual Studio. Off you go!  You've got a website to make faster!

Faster Website Conclusion

For additional recommendations grab the YSlow plugin.

About Oakwood

Since 1981, Oakwood has been helping companies of all sizes, across all industries, solve their business problems.  We bring world-class consultants to architect, design and deploy technology solutions to move your company forward.   Our proven approach guarantees better business outcomes.  With flexible engagement options, your project is delivered on-time and on budget.  11,000 satisfied clients can’t be wrong.

Like what you've read? Please spread the word!