ASP.NET Bundling - Bundle not updating after included file has changed (returns 304 not modified)
Solution 1:
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.
Solution 2:
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 (and BundleTable.EnableOptimizations = false or is omitted)
- By release mode i mean web.config compilation debug = false (and BundleTable.EnableOptimizations = true or is omitted
- Be sure you are actually making code changes. Changes such as spaces and comments do not affect the resulting minified js so the server is correct in that there are no changes (so the bundle cache is not refreshed).
Solution 3:
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.
Solution 4:
Okay, here's my story. I disabled generation of min files for less files in Web Essentials. Old min files were not deleted, and bundle thingy saw those instead of updated CSS. Good luck!
EDIT
Sometime later I spent another good 2 hours on the same issue. This time it was my fault I guess - I forgot the leading tilde, i.e. I wrote
Scripts.Render("/js/script")
in lieu of
Scripts.Render("~/js/script")
For whatever reason it sometimes worked, and sometimes it did no such thing.