IIS 8.0 add both Expires header and Cache-Control

2

i can see stackoverflow add's both Expires and Cache-Control for their images , css, js etc, so i am trying to do the same, i tried this article

web.config

<location path="Content">
    <system.webServer>
      <staticContent>

    <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" 
    cacheControlMaxAge="365.00:00:00" />

    <clientCache cacheControlMode="UseExpires" httpExpires="Mon, 01 May 2023 00:00:00 GMT" />

      </staticContent>
    </system.webServer>
</location>

when i try to acess a css file in content folder : http://localhost:11111/Content/bootstrap.min.css

i get the following error

Error:

HTTP Error 500.19 -

Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.

Module           CustomErrorModule
Notification     SendResponse
Handler          StaticFile
Error Code       0x8007000d

Config Error Configuration element 'clientCache' already defined

i know clientCache already defined, but i am concerned and want to know how to set both Cache-Control and Expires in response headers ?

Any help would be great.

Update:

As @Vitaly Kulikov answered and discussed in comment and using this and this posts i came to conclusion that in IIS we can's set both Expires and Cache-Control in web.config, so i have planned to use OutputCache to set Expires for images at least and it works with 0.9 milliseconds delay. Hope helps someone.

asp.net-mvc
caching
iis-8
cache-control
expires-header
asked on Stack Overflow Mar 13, 2016 by Shaiju T • edited May 23, 2017 by Community

1 Answer

3

According to the specification there is no way you can have both of them at the same time. But you have no reason to do that, you'll be fine with any of them.

Specification

If you look into Chrome source code, caching in browser has several simple rules

First:

The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply: freshness_lifetime = max_age_value

Second:

Otherwise, if Expires is present in the response, the calculation is: freshness_lifetime = expires_value - date_value

Third:

If we missed previous steps and "cache-control" != "must-revalidate", then browser has one more caching rule: It caches resource for 10% of a time passed since last modified date of a resource.

That's it, no more rules there.

answered on Stack Overflow Mar 16, 2016 by Vitaly Kulikov • edited Mar 16, 2016 by Vitaly Kulikov

User contributions licensed under CC BY-SA 3.0