MVC bundle EnableOptimizations

Bundling and minification are two techniques you can use to improve request load time.

Bundling is a ASP.NET 4.5 feature to combine multiples files into a single file. This is used in CSS and JavaScript files.
Minification performs code optimizations (ex: remove comments) to CSS and JavaScript files to reduce size.

Bundling and minification are enabled or disabled by default by setting to true or false the Compilation element.


To change this behavior use the BundleTable.EnableOptimizations property and set to true to enable bundling and minification.

Many times in a production environment you need something else to control the bundling and minification especially when you need to diagnose a problem in your JavaScript.

You can use any logic you want or, for a simple scenario, use a app settings key.


BundleTable.EnableOptimizations = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["EnableOptimizations"]);

Place this code in your BundleConfig class inside method RegisterBundles.

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *