4

TL;DR - I want the server (IIS 8.5) to return 304 not modified for the CSS and JS bundles.

I've been unable to get IIS 8.5 to honor the clientCache settings in web.config. No matter what I do, I can't seem to get it to cache the static content. This is a MVC5 app in VS2013. I've got all the static files in a folder "Assets".

The request looks like: http://someserver/AppName/Assets/mainjs?v=FNj_9ZPAbYVAQsyDo2F8XUnWv5NQpY4iX2RGu4NpJ5g1

  1. Attempt #1, place a new web.config in the Assets folder with the following:
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>
  1. Attempt #2: place this following configuration in the root web.config
<staticContent>   
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />    
</staticContent>
  1. Attempt #3: trying setting the cache using the location tag
<location path="Assets">
  <system.webServer>
    <staticContent>
      <clientCache  cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
    </staticContent>
  </system.webServer>
</location>

Here are the things I've tried in IIS 8.5 manager. Under the Default Web Site/TestApp

  1. HTTP Requeset Headers, Set Common HTTP Headers, check "Expire Web Content" "After 365 Day(s)".
  2. Apply the same setting to the "Assets" folder

I've tried these steps each on their own and all together and every other which way. No matter what, it won't add the max-age value to Cache-Control.

For each of these, the browswer returns 200 responses for the CSS and JS bundles. I cannot get the server cache the content coming from the Assets folder.

Cache-Control:private
Content-Encoding:gzip
Content-Length:22591
Content-Type:text/css; charset=utf-8
Date:Mon, 02 Feb 2015 21:49:49 GMT
Expires:Tue, 02 Feb 2016 21:49:49 GMT
Last-Modified:Mon, 02 Feb 2015 21:49:49 GMT
Persistent-Auth:true
Server:Microsoft-IIS/8.5
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
azymm
  • 312
  • 1
  • 8
  • What is the http response code for that request? – Ross Bush Feb 03 '15 at 01:34
  • The response codes for all JS and CSS is 200. I just now did a simple web app with just default.html and app.js, set the clientCache and the html file will get a 304, but the javascript will still return 200. So... there must be something preventing IIS setting the cache-control for specific file types? – azymm Feb 03 '15 at 01:44
  • Do you notice a change with your bundling versioning string? – Ross Bush Feb 03 '15 at 01:51
  • Seems to be staying the same - I just checked the js version again and it is the same as above FNj_9ZPAbYVAQsyDo2F8XUnWv5NQpY4iX2RGu4NpJ5g1. Also, I do have the `runAllManagedModulesForAllRequests` set to true currently. – azymm Feb 03 '15 at 02:03
  • I may be wrong but I think that file needs to be modified before a new version will be brought down. If the timestamp or content has not changed then there is nothing to re-up? Does that version change if you modify the js and recompile? – Ross Bush Feb 03 '15 at 02:07
  • It looks like the browser is downloading the file every request with a 200. However, I want the server to respond with 304 (not modified) for the bundled css and javascript. – azymm Feb 03 '15 at 02:37

1 Answers1

0

Check the individual files of the bundle. What do the files look like when you turn off optimizations? After you register your Bundles make a call to :

BundleTable.EnableOptimizations = (!HttpContext.Current.IsDebuggingEnabled);

OR

BundleTable.EnableOptimizations = false;

It could be that each file is coming back with a not modified. Does the status change when you refresh while in a debug session?

Ross Bush
  • 14,648
  • 2
  • 32
  • 55