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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With