Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • ASP.NET MVC - Get Started
  • MVC Architecture
  • MVC Version History
  • Create First MVC App
  • MVC Folder Structure
  • Routing
  • Controller
  • Action method
  • Action Selectors
  • ActionVerbs
  • Model
  • View
  • Integrate Model, View & Controller
  • Model Binding
  • Create Edit View
  • Razor Syntax
  • Html Helpers
  • Exception Handling
  • Validation
  • Layout View
  • Partial View
  • ViewBag
  • ViewData
  • TempData
  • Filters
  • ActionFilters
  • Bundling
  • ScriptBundle
  • StyleBundle
  • Area
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

Bundling and Minification

Bundling and minification techniques were introduced in MVC 4 to improve request load time. Bundling allows us to load the bunch of static files from the server in a single HTTP request.

The following figure illustrates the bundling technique:

Loading script files in separate requests

In the above figure, the browser sends two separate requests to load two different JavaScript file MyJavaScriptFile-1.js and MyJavaScriptFile-2.js.

The bundling technique in ASP.NET MVC allows us to load more than one JavaScript file, MyJavaScriptFile-1.js and MyJavaScriptFile-2.js in one request, as shown below.

Bundling and minification

Minification

Minification technique optimizes script or CSS file size by removing unnecessary white space and comments and shortening variable names to one character.

For example, consider the following JavaScript function.

Example: JavaScript
sayHello = function(name){
    //this is comment
    var msg = "Hello" + name;
    alert(msg);
}

Minification will remove the unnecessary white spaces, comments, and shortening variable names to reduce the characters, which will reduce the size of the JavaScript file. The above JavaScript will be minimized as the following script.

Example: Minified JavaScript
sayHello=function(n){var t="Hello"+n;alert(t)}

Bundling and minification impact on the loading time of the page.

Bundle Types

MVC 5 includes following bundle classes in System.web.Optimization namespace:

ScriptBundle: ScriptBundle is responsible for JavaScript minification of single or multiple script files.

StyleBundle: StyleBundle is responsible for CSS minification of single or multiple style sheet files.

DynamicFolderBundle: Represents a Bundle object that ASP.NET creates from a folder that contains files of the same type.

Learn about ScriptBundle in the next section.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.