.NET Daily


How to Add Expires Headers on an ASP.NET Website

Posted on .

How to Add Expires Headers on an ASP.NET Website


If you use YSlow plugin as an assistant to help you improve your website performance, you probably saw that by default you get an F grade on “Add Expires headers” section.

What exactly are Expires Headers?

Below is an explanation from Yahoo Developer website:

Browsers (and proxies) use a cache to reduce the number and size of HTTP requests, making web pages load faster. A web server uses the Expires header in the HTTP response to tell the client how long a component can be cached.

So the files targeted to set expires headers on them are mostly the static files from a website, like the images, CSS files or Javascript files.

How to Add Expires Headers?

There are quite few methods to do this. You can set the expires headers directly from IIS, you can write a custom HttpHandler or if you don’t want custom functionality you can set them from web.config file.

Below you have an example of how you can set the expiration date from web.config:

    <clientCache cacheControlMaxAge="30.00:00:00” 

The first number from cacheControlMaxAge field is the number of days. That is also the default value that I keep on my websites.

Note: In order to get an A grade from YSlow plugin, you have to set the value to more than 7 days.

ASP.NET - Expires Headers

ASP.NET – Expires Headers



Darius Dumitrescu is a creative Senior CMS Consultant with in depth .NET knowledge, focused on Web Development and Architecture Design.

  • user

    AUTHOR asshidiq

    Posted on 4:31 am July 3, 2019.

    thank you for the information, very useful

  • This site uses Akismet to reduce spam. Learn how your comment data is processed.

    View Comments (1) ...