Adding Expiration Date To Headers

I’ve been tweaking the performance of BlogEngine.NEXT today using my favorite tool: YSlow for FireBug. One of the things YSlow checks for is the expires HTTP header for static content such as images, script files and style sheets. Since BlogEngine.NET has always used custom HTTP handlers for serving scripts and stylesheets, only the static images have been a problem.

The problem

The problem is that with images on hosted environments on IIS 6, it’s impossible to control the serving of them without redirecting them through an HTTP handler. That’s not a good idea for several reasons:

  • It adds unnecessary overhead by going through the ASP.NET ISAPI
  • You need to add custom code to handle the requests
  • You need to change the URL from .gif to .gif.axd or similar

Here is what YSlow finds on my website that needs the expires header set to a far future date:

As you can see, it is all my static images that lacks the expires header.

The solution

If you run IIS 6 there is no good way of adding an expires header to images unless you have control over the IIS. If your site is hosted then you probably have no control at all. If you are using IIS 7 however, you can very easily add the header in your web.config’s system.webServer section like so:

 <clientCache httpExpires=”Sun, 29 Mar 2020 00:00:00 GMT” cacheControlMode=”UseExpires” />

What happens is that all static content will now have an expires HTTP header set to the year 2020. Static content means anything that isn’t served through the ASP.NET engine such as images, script files and styles sheets. This is one of the very easy tricks that will increase the performance of your site as well as your YSlow score.


Mads Kristensen
About Mads Kristensen
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

52 thoughts on “Adding Expiration Date To Headers

  1. Pingback:

  2. Pingback: mxkoedfurvxcbxcvdhfeye

  3. Pingback: vwemkfluygvzsdiohfse

  4. Pingback: czxmvxbjhegyfsegfvsdg

  5. Pingback: fmsdkugshfvjkdhfgvsdfvsdf

  6. Pingback: gklsdfngskjhgbjhxdvndshg

  7. Pingback: acsgvedhbnkmglhkmjnhjbvs

  8. Pingback: mcnfgxmrfshdchnfsxjrfsgdvfd

  9. Pingback: zcmvjnergujefvbfasdkjshvdfbv

  10. Pingback: gdsnxcrtkmfcffvshggsdfsvsd

  11. Pingback: fgkxcmfvsdffsdbvsesvsdfvsdv

  12. Pingback: raspberry ketones

  13. Pingback: forskohlii

  14. Pingback: review

  15. Pingback: raspberry ketones diet

  16. Pingback: Blue Coaster33

  17. Pingback: Scarves for Women

  18. Pingback: forskolin coleus forskohlii

  19. Pingback: madrid

  20. Pingback: dr oz fat burning pills

  21. Pingback: raspberry ketone diet

  22. Pingback: garcinia cambogia extract ultra

  23. Pingback: hcg solution

  24. Pingback: Ecom Masters FBA Edition Review

  25. Pingback: Guest Blogging

  26. Pingback: quantum vision system steps

  27. Pingback: quantum vision reviews

  28. Pingback: sigint system

  29. Pingback: kieliszki jako prezenty dla mlodej pary

  30. Pingback: BHP Opole

  31. Pingback: Warszawa ksiegowosc

  32. Pingback: yomega

  33. Pingback: grainger discount code may 2015 promo coupon off

  34. Pingback: Tienda

  35. Pingback: forskolin

  36. Pingback: play rainbow riches slot

  37. Pingback: streaming movies

  38. Pingback: watch tv show episodes

  39. Pingback: stream movies

  40. Pingback: watch movies online

  41. Pingback: stream movies

  42. Pingback: streaming movies

  43. Pingback: tv online, online tv

  44. Pingback: watch tv show episodes

  45. Pingback: free movie downloads

  46. Pingback: watch free movies online

  47. Pingback: dr oz weight loss supplement

  48. Pingback: pure forskolin extract

  49. Pingback: best fat burning pills

  50. Pingback: lotto srategies

  51. Pingback: e-commerce

  52. Pingback: Video Motion Pro review

Leave a Reply