2

I want to set up both expires and cachecontrol and httpExpires headers in web.config by following the answer on that question What's the difference Expires and Cache-control:max-age?

     <system.webServer>
        <staticContent>
            <clientCache cacheControlCustom="public" cacheControlMaxAge="12:00:00" cacheControlMode="UseMaxAge" />
            <clientCache cacheControlCustom="public" httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" cacheControlMode="UseExpires" />
        </staticContent>
    </system.webServer>

But for some reason images became not available when I am doing that.

I've got Failed to load resource: the server responded with a status of 500 (Internal Server Error) error on each image load (I can see that errors in browser dev tools console).

I guess I configure it wrong?

It would work if I comment any of clientCache section by leaving only single one

How to fix that?

UPDATED: Just asked one more related question how to set up both httpexpires and cachecontrol headers web.cofig:

Community
  • 1
  • 1
Sergino
  • 10,128
  • 30
  • 98
  • 159
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 30 '13 at 01:08
  • i have the same issue while using both `UseExpires` and `UseMaxAge`, did you find any solution, or can we use both ? – Shaiju T Mar 13 '16 at 09:20

2 Answers2

1

This IIS Client Cache page states that 'While the "Expires" and "max-age" settings are somewhat analagous, the "max-age" directive takes priority over "Expires"'. However, IIS generates HTTP 500 errors when one "max-age" clientCache entry was used in parallel with an "Expires" clientCache entry.

The "Expires" and "max-age" are mutually exclusive of one another when adjusting the "Set Common Headers" in IIS. You can use one or the other, but not both.

Other cache directives can be applied to subfolders or specific files in Web.config. See this stackoverflow page on configuring cache content in IIS7.

Community
  • 1
  • 1
JohnH
  • 1,920
  • 4
  • 25
  • 32
  • 1
    you can use one or other but i can see stack overflow set both "Expires" and "max-age" for their images and css etc , like: `Cache-Control:public, max-age=60` `Expires:Sun, 13 Mar 2016 08:05:18 GMT ` how do they do that ? when i use both in web.config i get 500 error internal server error. – Shaiju T Mar 13 '16 at 09:14
0
<staticContent>
        <clientCache cacheControlCustom="public;max-age" cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
</staticContent>
<urlCompression dynamicCompressionBeforeCache="true" />

This worked fine for me to cache a request for 10 days.

Javan R.
  • 2,011
  • 1
  • 19
  • 16