squishit gives 304 (not modified) instead of 200 (from cache)

1.4k views Asked by At

I am using "SquishIt" for combining my .js and .css files. The problem is that the squishit bundle results in a 304 (not changed) when all other resources are 200 (from cache). If I put the files in the regular way I get the wanted 200 result. An example of my code:

@MvcHtmlString.Create(@Bundle.JavaScript().Add("~/Scripts/Libs/jquery.cookie.js").Add("~/Scripts/Libs/jquery.dynatree.min.js").Add("~/Scripts/Libs/jquery.json-2.3.min.js").Add("~/Scripts/Libs/jsrender.js").Add("~/Scripts/Libs/jstorage.min.js").Add("~/Scripts/Common/utils.js").Add("~/Scripts/DataServices/AccountDataServices.js").Add("~/Scripts/AccountSelection.js").WithMinifier<SquishIt.Framework.Minifiers.JavaScript.MsMinifier>().Render("~/Scripts/AccSelectionscriptBandle_#.js"))

The result:

enter image description here

EDIT: I am using "Debug=false"; All other resources are 200 (from cache)

1

There are 1 answers

1
Mark Headley On BEST ANSWER

I believe you are on the right track, but you need to go one step further and add one more option to your clientCache setting (cacheControlCustom="must-revalidate"):

    <staticContent>
      <!-- A clients cache will expire 90 days after it is loaded -->
      <!-- each static item is revalidated against the server to see if the LastModifiedDate is different than the If-Modified-Since date-->
      <!-- http://msdn.microsoft.com/en-us/library/ms689443.aspx -->
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" cacheControlCustom="must-revalidate"/>
    </staticContent>

The cacheControlCustom forces a check against the server to compare the lastModifiedDate and the If-Modified-Since of the particular static file. Setting the cacheControlMaxAge will only get you so far, especially when you modify the file on the server, your client may not re-pull the file automatically. The setting you have (500 days) will only pull the file after it has been on the client's machine for 500 days. If that is your intention, great. (Also, SquishIt will mask some the caching behavior because changing a js/css file within a package, will generate a different hash name.)

The Url within the comment may explain a little more from MSDN.