Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net scriptbundle multiple include vs single include

What is the difference in bundling:

  bundles.Add(new ScriptBundle("~/bundles/jquery")
  .Include("~/Scripts/jquery-{version}.js","file2.js", "file3.js"));

vs

   bundles.Add(new ScriptBundle("~/bundles/jquery")
                .Include("~/Scripts/jquery-{version}.js")
                .Include("file2.js")
                .Include("file3.js"));

I can put many scripts inside the ONE include method or I can use many include methods.

When should I use what?

like image 493
HelloWorld Avatar asked Apr 21 '14 13:04

HelloWorld


2 Answers

Either choice is fine, it is a syntax, readability choice. Include("resource1", "resource2", "resourceN") is simple overload of the Include method that uses the params keyword. In C# the params keyword allows for a variable number of parameters.

Include('Resource1").Include("Resource2").Include("ResourceN") is a different signature of Include method that accepts one string argument. Include("resource1").Include("resource2") is simple chaining.

Either syntax ultimately calls the same code to add the "resource" string paths. You are just calling different signature/overloaded definitions of the Include method to pass your string resouce/js arguments.

like image 50
Brian Ogden Avatar answered Sep 28 '22 05:09

Brian Ogden


There is no difference.

In both ways you create a new ScriptBundle instance named "~/bundles/jquery" that includes all the files in the Scripts folder that match the wild card string "~/Scripts/jquery-{version}.js" and also "file2.js", "file3.js". Then you add the ScriptBundle instance to the BundleCollection instance named bundles using the Add method.

The {version} wild card matching shown above is used to automatically create a jQuery bundle with the appropriate version of jQuery in your Scripts folder. Allows you to use NuGet to update to a newer jQuery version without changing the preceding bundling code or jQuery references in your view pages.


For more info refer to Bundling and Minification.

like image 35
Akram Shahda Avatar answered Sep 28 '22 04:09

Akram Shahda