I want to include my JS scripts in a Bundle AND at the same time version them to avoid browser caching if those scripts have been changed.
Is there a "native" way with ASP.NET MVC 5 to accomplish this?
I've found a library called Cassette that does exactly this (automatically versioning the JS, which is a good thing) but I wanted something (even) simpler, without changing a lot my script configuration...
The following does not work:
var version = ConfigurationManager.AppSettings["cache"].ToString();
bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
"~/Scripts/framework.js" + version,
"~/Scripts/main.js"));
The result is that the "framework.js" file is not downloaded by the browser (probably is not found).
MVC will automatically add a version parameter for release builds (i.e. if debug="false" in web.config); see "Bundle Caching" here: http://www.asp.net/mvc/overview/performance/bundling-and-minification
You can explicitly enable this in debug builds (described in the same article), but your scripts will be minified as part of the same action; there's no separate method to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With