ASP.Net MVC 4 interview questions with answers: – What is Bundling and minification in Model view controller ?

In case you are new to MVC ( Model view controller) , you start seeing our videos on MVC by clicking the link  ASP.NET ( MVC ) Model view controller videos

As a web developer you may have created many Javascript and Css files. Many times to improve the modularity, readability and maintainability of the project we break single CSS/JS files into multiple files. This is an actually a good practice but performance wise bad practice.

In MVC 4 two small but useful features are introduced called, Bundling and Minification which make our website perform faster.

Bundlinglet us combine multiple javascript and css files into single element and that’s why just by a single a request we get multiple files.

Minification reduced the size of the file by minifying the content (i.e. removing not required blank spaces, removing comments, reducing identifiers). This is done at runtime. Because it also removes stuffs which are browser specific, for example if request is coming from IE it removes all Mozilla specific stuffs.

Steps for Bundling and Minification

1. Open BundleConfig.cs File

App1

2. In RegisterBundles write following code

publicstaticvoidRegisterBundles(BundleCollection bundles)
{
bundles.Add(
newScriptBundle(“~/jquery”).Include(
“~/Scripts/jquery-1.7.1.js”,
“~/Scripts/jquery-ui-1.7.1.js”,
“~/Scripts/jquery.unobtrusive*”,
“~/Scripts/jquery.validate*”));

bundles.Add(newStyleBundle(“~/css”).Include(
“~/Content/themes/base/jquery.ui.core.css”,
“~/Content/themes/base/jquery.ui.resizable.css”,
“~/Content/themes/base/jquery.ui.selectable.css”));
}

3.  Now in your View, instead of referencing individual files refer the bundle

<%=Scripts.Render(“~/jquery”) %>
<%=Scripts.Render(“~/css”) %>

Peformance Test using IE Developer tools

Before

App2

After

App3

Also do have a look on below video ASP.NET MVC Model view controller ( MVC) Step by Step Part 1:-


Thanks to www.questpond.com for providing this ASP.NET MVC interview question with answer.

Advertisements

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

One Response to ASP.Net MVC 4 interview questions with answers: – What is Bundling and minification in Model view controller ?

  1. OP says:

    Hi Guys,
    Nice article but little bit you have missed.
    Styles.Render(“~/css”)
    instead of
    Scripts.Render(“~/css”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s