StaticContent ClientCache Setting

I added the following to my web.config to enable 14 days image caching.

  <location path="Images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMaxAge="14.00:00:00" cacheControlMode="UseMaxAge" />
      </staticContent>
    </system.webServer>
  </location>

      

When browsing in chrome using F12 tools, I can see that the browser is still asking for an image from the server on refresh. It gets 304, so it doesn't load it again, but it still looks like a lost trip to the image on page refresh, etc.

Is this the correct behavior or should it, as I was expecting, just fetch from the cache based on the header it has for the file?

+3


source to share


1 answer


Cache management is server-side, not client-side. Therefore, the browser still has to ask the server for the file and receive 304

to know that it should use its cached copy.

Consider in the following HTML (which would be exactly the same whether the image is set to return from the cache), how does the browser know whether to load the image or use the cached version?



<img src="somefile.jpg" />

      

The client doesn't know because it doesn't look like the server that sets the tag cache-image="true"

on the tag img

that is displayed in the browser.

0


source







All Articles