How to enable bundling and minification in ASP.NET project?

Posted by Sheonarayan under ASP.NET MVC category on | Points: 40 | Views : 3097
To enable Bundling and Minification in ASP.NET project, we can follow below approach.

Approach 1
Set compilation debug mode to false in the web.config file.

<compilation debug="false" />
<!-- Lines removed for clarity. -->

Setting debug mode false to Compilation will automatically start bundling and minifying the .css and .js file. This only loads the .min version of the .js or .css file.

Approach 2

Set EnableOptimizations property of BundleTable to true. This will have the same effect as in Approach 1. Setting this property overrides the value of web.config compilation debug mode.

public static void RegisterBundles(BundleCollection bundles)
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(

// Below lines are important
BundleTable.EnableOptimizations = true;

Hope this code snippet will be useful.

Comments or Responses

Login to post response