ASP.NET Bundling - Bundle not updating after included file has changed (returns 304 not modified) ASP.NET Bundling - Bundle not updating after included file has changed (returns 304 not modified) asp.net asp.net

ASP.NET Bundling - Bundle not updating after included file has changed (returns 304 not modified)


I just had the exact same problem. I have a folder with 2 CSS files:

  • ~/Content/main.css
  • ~/Content/main.min.css (pre-existing from my previous manual minification process)

My bundling code is this:

bundles.Add(new StyleBundle("~/css/main").Include("~/content/main.css"));

No matter how much I changed my main.css the output was the same url with the same contents:

<link href="/css/main?v=6Xf_QaUMSlzHbXralZP7Msq1EiLTd7g1vId6Vcy8NJM1" rel="stylesheet"/>

The only way to update the bundle was to rebuild my solution - obviously not the best approach.

However as soon as I deleted main.min.css, everything started to work just fine. Playing a little more I discovered that if there are both main.css and main.min.css, then updating main.min.css will actually update the bundle... Weirdness, but at least predictable.


After fighting to figure out what makes the bundle cache refresh I came to a few conclusions that will hopefully help others:

If .min files ARE included as part of the bundle:

  • release mode + change min js code = cache refresh
  • release mode + change non min js code = no cache refresh
  • debug mode + change min js code = no cache refresh
  • debug mode + change non min js code = no cache refresh

If .min files are NOT included as part of the bundle:

  • debug mode + change js code = no cache refresh
  • release mode + change js code = cache refresh

Notes

  • By debug mode i mean web.config compilation debug = true (andBundleTable.EnableOptimizations = false or is omitted)
  • By release mode i mean web.config compilation debug = false (andBundleTable.EnableOptimizations = true or is omitted
  • Be sure you are actually making code changes. Changes such as spacesand comments do not affect the resulting minified js so the server iscorrect in that there are no changes (so the bundle cache is notrefreshed).


Please note that if you are using Google Chrome the caching is quite aggressive. To ensure nothing is cached, you can do Ctrl-Shift-I to bring up the developer pane. Go to Network and click Disable Cache. Ensure you keep this open. Now refresh the page. Your cache should be cleared and the file changes should be reflected now.

Disable cache in Google Chrome