Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Bundles take precedence over Routing?

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?

like image 919
Curtis Avatar asked Aug 29 '14 10:08

Curtis


People also ask

What is the advantage of bundling in MVC?

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.

How does bundling increase performance in MVC?

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.

How does bundling work in MVC?

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.

How do you override the bundling setting of web config?

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.


1 Answers

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.

like image 127
musefan Avatar answered Dec 01 '22 09:12

musefan