Adding Output Caching and Expire Header in IIS7 to improve performance

The problem:

Images and other static files will not be cached unless you tell it to. In IIS7 it is remarkably easy to do this.

Web pages are becoming increasingly complex with more scripts, style sheets, images, and Flash on them. A first-time visit to a page may require several HTTP requests to load all the components. By using Expires headers these components become cacheable, which avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often associated with images, but they can and should be used on all page components including scripts, style sheets, and Flash.

Every time a page is loaded, every image and other static content like JavaScript files and CSS files will be reloaded on every page request. If the content does not change frequently why not cache it and avoid the network traffic?!

The solution:

In IIS7 there are two ways to cache content, using the web.config file to set caching for all static content, and in IIS7 itself setting aching by file extension that gives you that extra level of granularity.

Web.config:

In IIS7, Expires Headers can be enabled in the system.webServer section of the web.config file:

  <staticContent>
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
  </staticContent>

In the above example a cache expiration of 1 day was added. It will be a full day before the content is downloaded from the web server again.

To expire the content on a specific date:

  <staticContent>
    <clientCache cacheControlMode="UseExpires" httpExpires="Sun, 31 Dec 2011 23:59:59 UTC" />
  </staticContent>

This will expire the content on December 31st 2011 one second before midnight.

Issues/Challenges:

Once the file has been set to be cached it wont be updated on the user's browser for the set cache expiration. So be careful here with content that may change frequently, like during development. Typically in development you don't want to cache at all for testing purposes. You could also suffix files with timestamp or versions to force a reload into the user's browser cache.

IIS7 Expire Web Content

Open up your web app in IIS. Open up the sub-folders until you find the folder or file you want to ad an expiration date to. In IIS6 you used to right-click and select properties, no such luck in IIS7, double click HTTP Response. Once the window loads for the HTTP Response Headers, look to the Actions navigation bar to the right, all the way at the top select SET COMMON HEADERS. The Enable HTTP keep-alive will already be pre-selected. Go ahead and add the appropriate expiration header to the file or folder. Note that if you selected a folder, it will apply that setting to all images inside that folder and all nested content, even subfolders.

So, two approaches, depending on what level or granularity you need.

Print | posted @ Wednesday, November 9, 2011 5:05 PM

Comments on this entry:

Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Hidayat at 4/30/2014 2:43 AM

I've been practicing it for my websites (jasa pembuatan toko online
significant changes in speed
thank you
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by nobelix at 7/2/2015 1:39 AM

Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work. naga poker
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by sedot wc jogja at 7/15/2015 12:46 PM

I wan to implementing on my site sedot wc jogja
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by tjterbaru at 9/2/2015 3:31 AM

very interesting post , I have tried to sell my web Jual Kacamata, first I get an error , but I finally managed to re- read . Thank you very much
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by tjterbaru at 9/2/2015 3:51 AM

I have tried to sell my web Jual Kacamata, first I get an error , but I finally readyng this post again. and work
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Seo Indonesia at 10/26/2015 10:49 AM

I enjoyed this post very much, such a out standing post. Marketing is a complex thing and there is no proper formula but constant engagement and efforts are the key of success. Seo Indonesia
Gravatar # # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by BPJS at 11/17/2015 7:24 PM

i like your article i want to implement the theory in my web BPJS
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Andy Yusuf at 11/27/2015 12:44 PM

Very helpful to my site here : Jasa Renovasi rumah di Malang
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Muktasir at 1/15/2016 12:41 PM

Hey there! This post couldn’t be written any better! Reading this post reminds me of my good old room mate! He always kept talking about this. I will forward this write-up to him. Fairly certain he will have a good read. Thank you for sharing! Jasa
Gravatar # re: www.yaakifaelegantas.comAdding Output Caching and Expire Header in IIS7 to improve performance
by tas seminar at 1/28/2016 9:48 PM

thank you ,for the informasion,and the picture is very interisting article,could to be learned
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by harteda at 2/27/2016 6:22 PM

I simply want to give you a huge thumbs up for the great info you have got here on this post. Tas Branded
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by ticen at 3/22/2016 9:20 AM

This article was very inspiring visitors
I hope there will be content to instruct the next content
You should also visit my web site at
Garden Statue Bali
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by familiar at 3/29/2016 5:45 AM

I enjoyed this post very much, such a out standing post. Marketing is a complex thing and there is no proper formula but constant engagement and efforts are the key of success. Seo Indonesia
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Emily at 4/5/2016 3:52 AM

Ah thanks for the solution. I aways wondering how to fix this in my IIS7. Don't know why, but this program seems to have many error and bugs. I really hope that the developer could fix this prolems ASAP. BTW is there any updates that I need to know about IIS7 program? If there's one, please let me know :)
Thanks,
Emily - Food & Catering Restaurant Jakarta
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Jeany at 4/12/2016 12:35 PM

Great and Lots of useful information,inspiration , Jam Tangan
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Training ISO at 4/21/2016 4:05 AM

Thank you for sharing sir, maybe i need to manage my website and adding output on my Training ISO is website.
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by mandowen jr at 7/19/2016 10:50 PM

I really enjoy simply reading all of your weblogs

poker online | agen poker
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Abahsaw at 7/25/2016 1:31 AM

I realy like reading this post very much, such a out standing post. Marketing is a complex thing and there is no proper formula but constant engagement . Catering Depok
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by redaf at 9/16/2016 1:34 AM

I have discovered a lot of helpful things out of this blog. I’d love to come back again soon.
Jual Tas Wanita
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by kacamata police at 11/12/2016 8:37 PM

informasi tentang kacamata police yang mantap abis
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Mariko at 11/14/2016 1:35 AM

no to my suprised that this way works so well, my site now load much faster! Pepes Ikan Mas Ibu Tatty
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by qwqew at 11/20/2016 12:07 AM

Through this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing pulsa elektrik termurah
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by sdfsadfsdf at 11/23/2016 4:15 PM

I really enjoy simply reading Ah thanks for the solution. I aways wondering how to fix this in my IIS7. Don't know why, but this program seems to have many error and bugs. I really hope that the developer could fix this prolems ASAP. BTW is there any updates that I need to know about IIS7 program? If there's one, please let me know :)
Thanks pulsa elektrik murah
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by yakub at 11/29/2016 3:59 AM

Thank you for sharing this information, very insightful. Don't forget to check out our blog about
baju golf!
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by dinero urgente at 12/11/2016 5:00 AM

thanks for sharing
creditos con asnef
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Dewapoker at 12/18/2016 11:07 PM

This is a very good post. Just wonderful. Truly, I am amazed at what informative things you've told us today

http://kimpoker.com | http://dewapoker888.net
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Natasya at 12/28/2016 9:51 PM

Amazing post ever...

Domino QQ
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Bryan at 12/28/2016 9:54 PM

Any update for this post? I hope there is an update
Judi Online
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Rega at 12/28/2016 9:56 PM

Wow Amzing Post !! , Btw Please visit my work at Taruhan Bola , lapak 303 , Poker Online thx for ur visit hope you like it
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by kenhchungcu at 5/20/2017 8:37 PM

thank for sharing!

the emerald
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Hanna at 10/16/2017 3:17 AM

great content! thanks for posting protect your family
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by Vanka at 1/15/2018 1:11 AM

i'm so amazed with your site! thanks for sharing best logistic company
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by ISO 17025 in Turkey at 4/12/2018 1:06 AM

A well written post will be the best thing for a reader. Your post has each of such quality which a perfect article requires. Keep writing more perfect article with same effort. custom essay writing service can give the affordable paper with high quality content.


ISO 9001 Certification in Egypt
Gravatar # re: Adding Output Caching and Expire Header in IIS7 to improve performance
by certvalue143 at 4/12/2018 6:08 AM

Hello...Extremely richly formed and helpful post!!!Great information shared!!!! Its reliably been value examining your post. I get such a large number of information of data from this discussion. Debts of gratitude are in order for doing this exploration and sharing this data it will genuinely pleasing for me and keep it up.
ISO 9001 Certification in Iraq
Post A Comment
Title:
Name:
Email:
Comment:
Verification: