Tutorialsteacher

Follow Us

Enable or Disable bundling and minification in MVC

Bundling and minification can be enabled or disabled in two ways: either setting the value of the debug attribute in the compilation Element in the Web.config file or setting the enableOptimizations property on the BundleTable class.

In the following example, debug is set to true in web.config to disable bundling and minification.

Example: Disable Bundling & Minification
<system.web>
    <compilation debug="true" />
</system.web>

Also, you can enable or disable bundling and minification by setting the EnableOptimizations property of the BundleTable class. This overrides the web.config settings.

In the following example, EnableOptimizations is set to true to enable bundling and minification.

Example: Enable Bundling & Minification
public static void RegisterBundles(BundleCollection bundles)
{            
    bundles.Add(new ScriptBundle("~/bundles/mysitescripts").Include(
            "~/Scripts/MyJavaScriptFile-1.js",
            "~/Scripts/MyJavaScriptFile-2.js",
            "~/Scripts/MyJavaScriptFile-3.js",
            "~/Scripts/MyJavaScriptFile-4.js",
    ));

    BundleTable.EnableOptimizations = true;
}