Search code examples
c#asp.net-mvcbundlebundling-and-minification

Does the ASP.net bundler automatically minify files?


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?)


Solution

  • The Asp.Net bundler does bundle all scripts in the same bundle into one single file, listed in the order they are defined in the bundle. This single file is then minified and delivered to the client.

    If you include both the normal and minified versions of a script in your script directory, the bundler will automatically deploy the full script during debugging sessions and the minified version during production. You should avoid referring to the minified versions of your scripts in the bundle configuration, unless you want the minified version deployed to your debug sessions.