Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC 5 sub-directory bundling issues

I am seeing a weird behavior with bundling in my ASP.Net MVC 5 project. My project works just fine when I explicitly declare all the files in my BundleConfig.cs file as follows:

bundles.Add(new ScriptBundle("~/bundles/app").Include(
                "~/app/app.js",
                "~/app/config.js",
                "~/app/dir1/file1.js",
                "~/app/dir1/subdir1/file2.js",
                .....

However, if I switch to use IncludeDirectory instead, the script paths during development (BundleTable.EnableOptimizations = false) are not complete. This is what I see:

bundles.Add(new ScriptBundle("~/bundles/app").Include(
                "~/app/app.js",
                "~/app/config.js")
                .IncludeDirectory("~/app/dir1", "*.js", true)

Chrome shows me a 404 when it is trying to get file2.js. The bundling system adds the following to my layout page:

<script src="/app/app.js"></script>
<script src="/app/config.js"></script>
<script src="/app/dir1/file1.js"></script>
<script src="/app/dir1/file2.js"></script>

The path to file2.js is wrong. It omits the subdir1 part of the path. Am I missing something here?

like image 661
mithun_daa Avatar asked Mar 24 '14 14:03

mithun_daa


People also ask

How do you use bundling and minification in MVC 5?

Bundling and minification is enabled or disabled by setting the value of the debug attribute in the compilation Element in the Web. config file. In the following XML, debug is set to true so bundling and minification is disabled. To enable bundling and minification, set the debug value to "false".

What are the two types of bundles in MVC 5?

You can see ScriptBundle and StyleBundle objects we are using for bundling the js and CSS types of files. ScriptBundle: is responsible for Script files i.e javascript (JS). StyleBundle: is responsible for stylesheet files i.e CSS.

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 do you override the bundling setting of web config?

Also, you can enable or disable bundling and minification by setting the EnableOptimizations property of the BundleTable class. This overrides the web. config settings. In the following example, EnableOptimizations is set to true to enable bundling and minification.


1 Answers

This is a known issue w/ version 1.1.1. Upgrade the package (or downgrade to 1.1.0) and it should fix your problem.

Web Optimization path issue while in debug mode

like image 115
Josh Avatar answered Oct 19 '22 03:10

Josh