Bundling and Minification in C#


In this article I will take you through bundling and minification concepts and why to use and apply these standards in your code as a developer.


  1. Overview
  2.  Need | Analysis
  3. Comparative Study
        • Before Web Optimization
        • After Web Optimization
  4. Introduction
  5. Techniques
  6. Bundling
        • Procedure
        • Comparison
        • Bundling | Features
  7. Minification
        • Minification | Features
        • Snippet
  8. Controlling
  9. Other Techniques
  10. Summary


Peoples are enjoying coding these days, they are ionate about coding. It doesn't matter what they code and in which language, the thing that really matters these days is code optimization and how efficiently and effectively your code performs certain required actions.

Need Analysis

As I explained, coding is now not an issue for developers these days, the main thing in a development environment is what your code will do and how effective it is in a real scenario.

In this article I will explain how to make our code efficient and work better depending on the required set of operations (I am explaining it the context of C#, you can also explore for your favorite language).

Comparative Study

This part of this article will show a real picture of web optimization. This picture contains two parts, the first part shows the web before ASP.NET web optimization techniques and the other picture shows the web scenario after the web optimization technique usage.

Here's the scenario.

Before WEB Optimization

image[Before WEB Optimization]

[Scenario: 1]

After WEB Optimization

Image[After WEB Optimization]

[Scenario: 2]


For solving these types of complex problems and getting the desired result effectively, .NET provides super functionality for resolving all of these kinds of problems.

These factors are:

  • Reducing request to the server
  • Minimizing size of requests


For handling those two issues, or we can say operations, for web framework optimization, we do use these two major techniques:

Image[For handling those two]


In the bundling procedure ASP.NET minimizes or bundles the requests to the server depending on their functionality, so that the traffic at the sever can be easily handled.

The diagram below shows the comparative mechanism of how actually the requests were working before bundling and in the second diagram it shows the mechanism of handling requests, after use of the bundling concept.




The following shows the simple difference of functioning:

Before Bundling:

Image[Before Bundling]

After Bundling:

Image[After Bundling]

Bundling Features

Some of the most useful features of bundling are as follows:

  • Comes into light with ASP.NET 4.5
  • Functionality Oriented
  • Reduces traffic at the server
  • Bundles the similar type of requests
  • Improves page load operation
  • Works with single resource


Minification is the process in which we try to minimize the size of requests to the server. It minimizes the load event handling at the server side.

Minification Features

Some most useful features of minification are as follows:

  • Comes into light with ASP.NET 4.5
  • Functionality oriented
  • Reduces size of request to the server
  • Improves performance of load event


We can control these processes by simply enabling it in the web config file as in:

  1. <!-- Enabling-->  
  2. <system.web>  
  3.     <compilation debug="true" targetFramework="4.0" />  
  4. </system.web>  
Then for enabling functionality we need to add this:
  1. public static void EnableBundles(BundleCollection bundles)  
  2. {  
  3.     bundles.Add(new ScriptBundle("Path").Include(  
  4.     "Path-{version}.js"));  
  5.     BundleTable.EnableOptimizations = true;  
  6. }  
Other Techniques

Some other techniques of ASP.NET Web optimization are:

Image[Web Optimization]


This article was a summary of Bundling and Minification. Mostly bundling I say, more of the functionality of the Minification operation will be added soon.

Until now, happy coding.

Similar Articles