Is there a reason to have multiple ScriptBundle packages in BundleConfig?

Here's the default MVC5 value of the BundleConfig application:

public class BundleConfig { // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.validate*")); // Use the development version of Modernizr to develop with and learn from. Then, when you're // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( "~/Scripts/modernizr-*")); bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/Scripts/bootstrap.js", "~/Scripts/respond.js")); } } 

Wouldn't it be easier to have only one kit, where you will include all the scripts you need? eg:

 public class BundleConfig { // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/scripts").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/jquery.validate*", "~/Scripts/modernizr-*", "~/Scripts/bootstrap.js", "~/Scripts/respond.js")); } } 

Or, which is even simpler, for example, (in the Script folder, you put only JS files):

 public class BundleConfig { // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/scripts").Include("~/Scripts/*")); } } 
+6
source share
2 answers

Wouldn't it be easier to have only one kit, where you will include all the scripts you need?

This can simplify the development process a bit, since you do not need to look for the appropriate package to include. But let's look at it from a different perspective.

The asp.net forum has the following: w / w>

Binding and minimization are two methods that you can use in ASP.NET 4.5 to improve query load time. Combining and minimizing improves load time by reducing the number of requests to the server and reducing the size of the requested assets (for example, CSS and JavaScript.)

So, we are going to make the job faster. What to do if you created a page with a simple form where bootstrap.js is not required. Why would you download it if you are interested in speeding everything up?

The best option is to have all possible combinations of js files that may be needed in one place in separate packages. Each page makes only one request to get all the js it needs. However, this way of things is quite difficult to maintain.

So, you decide which aspect is of interest to you.

+5
source

Association:. This is a group of js and css files that can be attributed to a unique name.
Purpose: The main use of the package is to download one HTTP request instead of several requests for each file.

Minification: The main process is removing unnecessary spaces from js and css files. Purpose: The main goal is to remove line breaks and comments from code and increase load time by reducing file size.

You will find more information below.

http://dotnet-helpers.com/mvc/bundlingminification/

0
source

All Articles