Does the ASP.net bundler automatically minify files?

AlbatrossCafe picture AlbatrossCafe · May 19, 2015 · Viewed 14.9k times · Source

I'm using ASP.net MVC 4. Like the question states, if I put a bunch of JS files (or CSS, for that matter) into a bundle, will it automatically be minified? For example, should my bundle read:

        bundles.Add(new ScriptBundle("~/bundles/exampleBundle").Include(
            "~/Scripts/jquery-masked.js"
            "~/Scripts/jquery.idletimer.js"
            ));

Or should it instead include the minified files initially:

        bundles.Add(new ScriptBundle("~/bundles/exampleBundle").Include(
            "~/Scripts/jquery-masked.min.js"
            "~/Scripts/jquery.idletimer.min.js"
            ));

??

Edit: Now I am wondering if bundling the .min files instead adds any optimization. Will it increase performance including the .min files in the bundle instead of the basic files? (Maybe the "minifier function" takes some time?)

Answer

Claudio Redi picture Claudio Redi · May 19, 2015

You don't have to include minified files, that's automatically done by bundle engine. In fact, I remember including minified files caused problems (maybe this is fixed on latest mvc version)

You may think this is not working since optimizations (bundling and minifying) are only performed when debug=false on web.config.

<system.web>
     <compilation debug="false" />
</system.web>

There is a way to force optimizations even when debug = true using BundleTable.EnableOptimizations. Here you have an example

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));

    BundleTable.EnableOptimizations = true;
}