MVC 4 BundleConfig does not create script links

I am adding several jQuery script files to my application using the bundleconfig.cs class.

bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/jquery-ui-{version}.js", "~/Scripts/jquery.mCustomScrollbar.min.js", "~/Scripts/jquery.mousewheel.min.js", "~/Scripts/jtable/jquery.jtable.js")); 

When I launch my application and check the source of the page, only some of the script files are referenced:

 <script src="/Scripts/jquery-1.10.2.js"></script> <script src="/Scripts/jquery-ui-1.10.3.js"></script> <script src="/Scripts/jtable/jquery.jtable.js"></script> <script src="/Scripts/jquery-migrate-1.2.1.min.js"></script> 

Why is this happening? I can work around the problem by manually adding script links directly to _Layout.cshtml, but this is hardly the best practice.

+6
source share
2 answers

The .min part is already being processed by MVC - it automatically includes .js files for debug mode and .min.js . for release mode.

Just download the uninstalled version of jquery.mCustomScrollbar.min.js and put it in your script directory and then specify it as: jquery.mCustomScrollbar.js

 bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/jquery-ui-{version}.js", "~/Scripts/jquery.mCustomScrollbar.js", "~/Scripts/jquery.mousewheel.js", "~/Scripts/jtable/jquery.jtable.js")); 

Then MVC will load the appropriate script for debugging / release

+14
source

This may be because you did not enable binding. Try changing the debug attribute value during compilation to false

 <compilation debug="false" targetFramework="4.0" /> 

Or enable it manually:

 BundleTable.EnableOptimizations = true; 
+2
source

Source: https://habr.com/ru/post/949454/


All Articles