If I have a Bundle such as:
bundles.Add(new ScriptBundle("~/foo/bar").Include(
"~/Scripts/foo.js"));
And a Route such as:
routes.MapRoute(
"Foo", // Route name
"foo/bar",
new
{
controller = "Foo",
action = "Bar"
});
Which one will take precedence?
Will the browser return the ScriptBundle
or the ActionResult
?
Bundling and Minification provide us a way to both reduce the number of requests needed to get JS and CSS resource files and reduce the size of the files themselves, thereby improving the responsiveness of our apps. They are nice little optimizations for our MVC apps that can improve performance and add responsiveness.
To improve the performance of the application, ASP.NET MVC provides inbuilt feature to bundle multiple files into a single, file which in turn improves the page load performance because of fewer HTTP requests.
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. In the above figure, the browser sends two separate requests to load two different JavaScript file MyJavaScriptFile-1.
To enable bundling and minification, set the debug value to "false". You can override the Web. config setting with the EnableOptimizations property on the BundleTable class. The following code enables bundling and minification and overrides any setting in the Web.
If you read this post, it has been suggested that the bundle route (url) will take priority:
Clearly the default route with /content/css path matches the css action but the bundling framework will override the http handler.
The post also recommends the convention of prefixing "bundle" to all bundle paths. For example:
bundles.Add(new ScriptBundle("~/bundle/foo/bar").Include(
"~/Scripts/foo.js"));
The post referenced above is linked in this tutorial, which has a section near the bottom called "Bundle Considerations" which might be of interest.
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