Adding Expiry Header to Static Files in ASP.net

In a previous article I discussed how to optimize your ASP application via HTTP Compression. In this article I will demonstrate how to save bandwidth and make your page load faster by adding expiry header to static files in ASP.net.

Usually, you can cache static files such as images, stylesheets and script files. By making some changes in the web.config file, we can set the browser to cache all these files.

Add this code to your web.config which will cache all static files of your application in the browser for 2 years:

<system.webServer><staticContent>
      <clientCache cacheControlCustom="UseMaxAge" cacheControlMaxAge="730.00:00:00"/>
    </staticContent> </system.webServer>

1
This setting is very useful if you don’t make style changes in your ASP application. Nevertheless, if a user makes a hard refresh (Control + F5) on his web browser, the cache will be updated. Most users don’t do hard refreshes, and this code will make your application load faster.

This concludes Adding expiry header to static files in ASP.net

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

Happy Hosting!

Rodolfo Hernandez

Tags: , , , , , , , , , , , , , , , , , | Posted under ASP .NET 3.5, DotNet/Windows Hosting, WebsitePanel Tutorials | RSS 2.0

Author Spotlight

Rodolfo Hernandez

Rodolfo Hernandez

I like photography and reading books. Currently working for Arvixe as Elgg Community Liaison. Elgg Security Expert Web Security Expert CEO of UDP SW Social Web

Leave a Reply

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


5 × = 20

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>