Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 411
AlbatrossCafe Avatar asked May 19 '15 16:05

AlbatrossCafe


People also ask

How does bundling use browser cache capability?

Busting Browser's Cache by Bundling As we upload the changes in the static resources such as CSS and JS files on the live server, the resources changes but it does not update on the Browser, because the Browser's cache resources are based on URLs automatically.

What is true about bundling and minification in asp net core?

Bundling and minification are two distinct performance optimizations you can apply in a web app. Used together, bundling and minification improve performance by reducing the number of server requests and reducing the size of the requested static assets.

What is difference between bundling and minification?

Bundling and minification are two techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads.

How does bundling work in MVC?

Creating a Bundle in MVCBundling can create separate requests for CSS and JavaScript files. For example, if an application uses both the bootstrap and site CSS for UI design, we can create a common bundle for them. After Bundling, we need to register this bundle in the Application.


1 Answers

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; } 
like image 153
Claudio Redi Avatar answered Sep 28 '22 08:09

Claudio Redi