QuestPond: Interview Questions and Answers on learning ASP.NET MVC (Model View Controller)

What is Bundling and Minification in ASP.NET MVC?

Bundling

In normal scenario let say for an instance,

  •  User makes a request to index action in customer controller.
  • Action method will return a view result.
  • Now the view contains reference to 3 js files and 3 css files.
  • When browser receives the view in response, it comes to know about these references so it will make 6 more requests to server asking for the referenced files.

It will affect the overall response time of the view. To get one complete view browser makes 7 requests (one for view, 3 for js and 3 for css). Now imagine the situation when we have more number of css and js files. 🙂 🙂

Bundling is the solution for the same.
It let us combine multiple files into one file at runtime. Using this concept we can create bundles of js and css files. Fewer files mean fewer response times and it means quick response time.

Minification

Normally how we write or JavaScript and css. We follow following rules normally while writing css or js.

  • We use proper indentation
  • We properly add spaces
  • We use enter properly
  • We use meaning full names for defining variables
  • Write comments wherever we write complex logic

What next? 😦 It will affect the size of the file. File size will be increased and thus increased download time.

Solution is Minification. Minification is a technology which will reduces the size of the file at runtime by removing unnecessary whitespaces, comments and shortening variable names.

How to perform bundling and Minification?

Step 1: Add reference of System.Web.Optimization to your project

Step 2: In global.asax create the bundles as follows

BundleTable.Bundles.Add(new ScriptBundle("~/bundles/jquery").
Include
("~/Scripts/jquery-2.1.1.js", "~/Scripts/jquery.validate.js", 
"~/Scripts/jquery.validate.unobtrusive.js"));

Step 3: Enable optimization in global.asaxasfollws

BundleTable.EnableOptimizations = true;

Step 4: In the view include bundle as follows

@Scripts.Render("~/bundles/jquery")

index

 

 

 

 

For technical trainings on various topics like WCF, MVC, Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com

For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

See following video on implementing ASP.NET (Model View Controller) MVC Web API: –

 

If you want to learn more about bundling and Minification then go through following video from our www.QuestPond.com






About C#.NET, ASP.NET MVC Core, Angular, Azure, (MSBI)Business Intelligence, Data Science - Python 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. ASP.NET MVC Interview Questions and Answers:- https://youtu.be/pXmMdmJUC0g C# Interview Questions and Answers:- https://youtu.be/BKynEBPqiIM Angular Interview Questions and Answers:- https://youtu.be/-jeoyDJDsSM C# tutorial for beginners(4 hrs.):- https://youtu.be/AxEGRBFwlmI Learn Azure Step by Step:- https://youtu.be/wdUK7bCMXqs Azure AZ-900 fundamentals certification :- https://youtu.be/hC9iGgJorz8 AZ- 204 certification Azure:- https://youtu.be/qI8PRn2C080 Learn Angular tutorial step by step https://tinyurl.com/ycd9j895 Learn MVC 5 step by step in 16 hours:- https://youtu.be/Lp7nSImO5vk Learn Design Pattern Step by Step https://goo.gl/eJdn0m Learn MSBI Step by Step in 32 hours:- https://goo.gl/TTpFZN Learn SQL Server Step by Step http://tinyurl.com/ja4zmwu Python Tutorial for Beginners:- https://youtu.be/KjJ7WzEL-es Learn Data Science in 1 hour :- https://tinyurl.com/y5o7qbau Learn Power BI Step by Step:- https://tinyurl.com/y6thhkxw Learn Tableau step by step :- https://tinyurl.com/kh6ojyo
This entry was posted in Uncategorized and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a comment