Set Expiration Dates on Web Assets

If you have been following any of my articles you will know that I am always looking for ways to improve performance. Nothing is more frustrating than to go to a site and it seems like an eternity to load. This little helpful hint not only will increase performance but also minimize bandwidth requirements.

If you are like me than you have a multitude of images that rarely change on a site. Many of them are used in layouts, buttons, navigation, etc. If you do have a lot then why not tell the browser to use the images that have already been downloaded before. Once again in IIS 7 you can add the following to your web.config. It’s in the system.webServer section.

    <clientCache httpExpires="Sat, 21 Sep 2013 00:00:00 GMT" cacheControlMode="UseExpires" />

This will cause static content to be tagged with an expiration date of September 21. 2013. Once this hits then the next time a user comes to the site it will deliver the image again.

Although this is an acceptable way, this means that you will have to go and change the expiration date once September 21, 2013 comes along. I actually prefer to use this syntax.

    <clientCache cacheControlMaxAge ="5.00:00:00" cacheControlMode="UseMaxAge" />

This sets the static content to expire 5 days from today. So in theory, if a user comes to your site every 5 days then they would download the static content again.

It is important to realize that the definition of static content is anything that is not served through the ASP.NET engine. This means that things like images, style sheets, javascript files, etc will not be downloaded before the expiration date.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , | Posted under ASP .NET 4.0, Programming/Coding | RSS 2.0

Author Spotlight

David Bauernschmidt

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

Leave a Reply

Your email address will not be published. Required fields are marked *