Sunday, October 14, 2012

Bundling and Minification with MVC 4.0

With MVC 4.0 few new features has been introduced like 
  • web APIpport
  • Enhanced support for asynchronous methods
  • Mobile project support
Bandling and Minification is the most exiting feature

Now a days developer using different JS plagins and and css files to provide rich look to web application. That while loading web page browser require to request more number of resource files

Most of the browser support maximum six connections at a time to the server and  other resources has to wait for download completion

Bundling is combine the multiple files in to single file and decress the no of file and less number of file incress the pgae load performance.

Minification performs a variety of different code optimizations to scripts or css, such as removing unnecessary white space and comments and shortening variable names to one character.

minification example :
actual code
function test(value1, value2)
   return value1+value2;

minified code
function a(b,c){return a+b;}

Some of open source Javascript code provide minification version to improve the performance like Jquery, Jquery Mobile, modernizr etc.

While .net minification is developing minified version by the it self. Developer can control the which version either to serve minified version or full version of JS

Developer can contorl it using web.config

 debug="true" />

or by specifying following value while registering bundle

BundleTable.EnableOptimizations = true;

I have found some problem and also find some solution on stack overflow :

  • .net it self minified the script 
  • .net not render the script .min version
Jquery Mobile .net minified version not works on opera desktop browser as well opera mobile browser the Problem and solution are explain in below link

mvc4 bundler not including .min files 

Those features are already in used but .net has integrate this development and make development and deployment easy and save time.