Google’s various page speed testing tools seem to prefer browser caching set with at least a one week expiration set. That makes great sense to me! Setting a browser cache expiration tells the visitor’s browser that is is okay to cache the content – so upon the next visit the browser will load the content from local cache rather than requesting it from the server again. That’s a big win on a couple different fronts:

1. Page Load Speed. If the page, or at least parts of the page, are loaded from cache, that is always going to display faster than a round-trip to the server. And the faster the visitor’s browsing experience is, the better the overall experience and site impression will be. Site load time has shown to have a large impact on visitor interaction with web sites.

2. Bandwidth / Data Transfers. If the data is pulled from cache rather than the server, that obviously means less data being transferred. In a case where bandwidth is tracked and allocated on a monthly data transfer plan, this means less overall usage and potentially less costs for your hosting. This would be especially important in sites that are image-heavy like perhaps storefronts that show images of varying size and quality for their products.

3. Site / Server performance. If something is loaded from cache rather than from the server, that cuts down on the number of requests that the site needs to satisfy. Sure, even the smallest of servers can commonly handle hundreds if not thousands of concurrent visitors, but hey, why make it do all that work if it doesn’t need to? Imagine if your content is all cached and you have a 50% new vs returning visitor ratio… that means that your site load would potentially be cut in half, and the server could handle twice as many visitors before needing a resource upgrade. Score!

OK. Are you sold on the idea yet? If so, here’s how to adjust this setting in IIS 7.5 (Windows Server 2008 R2 hosting)…

First open the IIS Manager on your server, expand the Sites folder and then find the site you want to manage. You can control the caching either for the entire site or for specific folders. The interface and steps are basically the same, but I’ll show screenshots of making the change just on the \images\ folder of my test site:

Compression setting in IIS

Once you select the folder you’ll see a bunch of standard option icons. You want to look for the HTTP Response Headers icon in the IIS section of the IIS Manager interface. I’ve highlighted it in red above.

Once you double-click on that icon you’ll see the interface change:

Set Common Headers in IIS

From this interface you’ll want to select the option in the right-hand pane to Set Common Headers. Clicking that link brings up a dialog box to set just two common header items with a few option settings:

The Common Header settings and options in IIS

The HTTP Keep-alive should be already selected by default – leave that alone. Let’s pay attention to the Expire Web Content option which isn’t selected by default. Once you check that box you’ll see that it defaults to expiring the content immediately… which is not helpful at all. Choose the radio button for “After” then set a date range. Google seems to prefer this caching option set to at least one week so I commonly set it to 8 days as shown in my sample image.

Click OK to save the settings and you’re all done! You can test your site using browser (IE or Chrome) developer tools to confirm the headers, or use an external testing site to confirm the caching.

I hope you find this helpful – Happy Hosting!
Brad on Google+

Be Sociable, Share!
    Enable Caching in IIS to Speed Performance
    Tagged on:                     

    10 thoughts on “Enable Caching in IIS to Speed Performance

    • Pingback: Enable Caching in IIS to Speed Performance - ASP.NET and Silverlight

      • April 17, 2012 at 2:42 pm
        Permalink

        While this might look to some like comment spam, and maybe it is (:>), I’m approving it and will add the note that I’ve actually used the Port80 software in the past and it’s worth looking into if you have more complex caching requirements.

        • April 17, 2012 at 4:10 pm
          Permalink

          Thanks Brad. We try to tread carefully with these types of comments, but your post seemed very relevant.

          Also, another useful resource for caching guidance are Mark Nottingham’s caching tutorials: http://www.mnot.net/cache_docs/

    • Pingback: The Morning Brew - Chris Alcock » The Morning Brew #1087

    • Pingback: IIS7 Posts You Don't Want to Miss | Ponderings - Various Topical Thoughts by Brad Kingsley

    • February 22, 2013 at 1:39 pm
      Permalink

      Since you are familiar with IIS7 Web Site administration, I was wondering if you could help me out.

      Our Team is building a C# project with a Silverlight module. We deploy to a Windows 2008 with IIS 7. I’m trying to Programmatically Expire the HTTP Response Headers Associated with a Folder called ClientBin immediately. I know how to do it manually through IIS Manager. ( Basically, I go to the HTTP Response Headers Section of the folder or file that is of interest, and then I use “Set Common Headers….” to expire immediately.) However, we will be Redeploying to IIS a number of times, and I want to ensure that it is programmatically done because it’s a headache to keep Reconfiguring all the time.

      Should I do it from the C# code of my project or is it better practice to do it using WMI scripting and/or PowerShell?

      Could someone please assist?
      Thanks,

      Web Developer

    • March 2, 2013 at 5:22 am
      Permalink

      Nice article Brad!!
      The little stuff makes the people happy although they not notice it :wink:

    • April 11, 2013 at 7:31 am
      Permalink

      Thanks Brad. Very good article!

    • Pingback: NEW MEDIA BUSINNES SOLUTIONS SEO for Beginners: Improving Site Speed

    Comments are closed.