I don't know if I'm doing something wrong but it's probably a bug inside MVC4. I wonder how can I fix this?
public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { ScriptBundle scriptBundle = new ScriptBundle("~/js"); string[] scriptArray = { "~/content/plugins/jquery/jquery-1.8.2.min.js", "~/content/plugins/jquery/jquery-ui-1.9.0.min.js", "~/content/plugins/jquery/jquery.validate.min.js", "~/content/plugins/jquery/jquery.validate.unobtrusive.min.js", "~/content/plugins/bootstrap/js/bootstrap.min.js", }; scriptBundle.Include(scriptArray); scriptBundle.IncludeDirectory("~/content/js", "*.js"); bundles.Add(scriptBundle); BundleTable.EnableOptimizations = true; } }
@Scripts.Render("~/js")
Converts to (e.g. IT WORKS!) <script src="/js?v=VeCPNK561DZp34yjmWbLrNM35Kf6gaNDl0xsMMC25BQ1"></script>
public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { ScriptBundle scriptBundle = new ScriptBundle("~/js"); string[] scriptArray = { "~/content/plugins/jquery/jquery-1.8.2.min.js", "~/content/plugins/jquery/jquery-ui-1.9.0.min.js", "~/content/plugins/jquery/jquery.validate.min.js", "~/content/plugins/jquery/jquery.validate.unobtrusive.min.js", "~/content/plugins/bootstrap/js/bootstrap.min.js", }; scriptBundle.Include(scriptArray); scriptBundle.IncludeDirectory("~/content/js", "*.js"); bundles.Add(scriptBundle); // BundleTable.EnableOptimizations = true; // I could set it to 'false' for same result, it's false by default } }
@Scripts.Render("~/js")
Converts to (e.g. IT DOES NOT WORK!) (nothing, couple of empty break lines)
To enable bundling and minification, set the debug value to "false". You can override the Web. config setting with the EnableOptimizations property on the BundleTable class. The following code enables bundling and minification and overrides any setting in the Web.
Both bundling and minification are the two separate techniques to reduce the load time. The bundling reduces the number of requests to the Server, while the minification reduces the size of the requested assets.
BundleConfig.cs Shown below is the BundleConfig. cs file present in a default MVC5 application. This file contains RegisterBundles() method which is being called at Application_Start() event by global. asax.
Bundling and Minification are two performance improvement techniques that improves the request load time of the application. Most of the current major browsers limit the number of simultaneous connections per hostname to six. It means that at a time, all the additional requests will be queued by the browser.
If my understanding is correct, you should define your bundles using the "non-min" JavaScript files. When you enable optimizations it will swap the non-min files for the min files for you:
public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { ScriptBundle scriptBundle = new ScriptBundle("~/js"); string[] scriptArray = { "~/content/plugins/jquery/jquery-1.8.2.js", "~/content/plugins/jquery/jquery-ui-1.9.0.js", "~/content/plugins/jquery/jquery.validate.js", "~/content/plugins/jquery/jquery.validate.unobtrusive.js", "~/content/plugins/bootstrap/js/bootstrap.js", }; scriptBundle.Include(scriptArray); scriptBundle.IncludeDirectory("~/content/js", "*.js"); bundles.Add(scriptBundle); } }
Optimizations are set to false when debugging, but are true by default in release mode.
yes, It doesn't work properly with files like *.min.js.
"if you add a file to your bundle that has a name that ends in .min.js (like I did) and optimizations aren’t enabled (e.g. debug is set to true in web.config and BundleTable.EnableOptimizations has not been set to true), this file will be ignored (i.e no script include will be generated for it in your html)."
Here you can read full original response: http://blog.degree.no/2013/06/javascript-file-missing-resource-bundle-asp-net-web-optimization-framework/
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