1.

What is Bundling and Minification in MVC

Answer»

The majority of the websites are making use of Javascript and CSS files to improve the usability and look and feel of websites. So often on these pages, you will find multiple <script> and <link> tags. Each time the browser runs across these tags, make the CALL to the server to download the respective script and CSS files.  

So the number of Javascript and CSS files in our application, more the requests made to the server which leads to increase the time to load the page and make it functional.

In MVC 4.5 TWO new techniques are introduced to reduce these requests and improve the request load time. These two techniques are:

  1. Bundling
  2. Minification

Bundling

As the name says, Bundling combines the multiple files of the same type into a single file. So like if we have multiple script files use in an application, Bundling will combine all these script files into one single script file. Since the number of files is reduced, hence the number of HTTP requests is also reduced and this can improve first-page load performance.

In MVC Application there is a file called BundleConfig.cs in App_Start folder where we can add similar files into one bundle. We can add/register multiple bundles here.

Minification

Minification technique helps to reduce the size of the files. This technique applies to the bundled files. It applies various code optimizations to SCRIPTS and CSS like reducing/removing unnecessary white SPACES and comments, shortening VARIABLE names.

We can enable/disable Bundling and minification through Web.config file as: 

<system.web> <compilation debug="true" /> <!-- Lines removed for clarity. --> </system.web>


Discussion

No Comment Found