Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Script bundle not rendered

I've included the following line in the BundleConfig.cs file:

bundles.Add(new ScriptBundle("~/bundles/jqueryajax").Include(
  "~/Scripts/jquery.unobtrusive-ajax.min.js"));

However when I try to render it among other scripts, it's skipped.

Here is how I render the scripts:

@Scripts.Render(
    "~/bundles/jquery",
    "~/bundles/jqueryui",
    "~/bundles/jqueryajax",
    "~/bundles/jquerytree")

This is the output HTML, the jqueryajax bundle is omitted:

<script src="/Scripts/jquery-1.9.1.js"></script>
<script src="/Scripts/jquery-ui-1.10.2.js"></script>
<script src="/Scripts/jquery.jstree.js"></script>
like image 515
Shimmy Weitzhandler Avatar asked Apr 30 '13 05:04

Shimmy Weitzhandler


People also ask

What is BundleConfig cs in asp net MVC?

Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load performance.

How minification is implemented in MVC?

Bundling and minification can be enabled or disabled in two ways: either setting the value of the debug attribute in the compilation Element in the Web. config file or setting the enableOptimizations property on the BundleTable class. In the following example, debug is set to true in web.

What is the use of WebGrease?

What is WebGrease? It is primarily a command line tool and named as WG. EXE and provide all the above said features. This tool also can be use in pre or post build event to leverage the features.


1 Answers

I believe ScriptBundle tries to minify the file when debug="false" instead of using the existing .min.js file. There is a setting in web.config to affect how this works (set usePreMinifiedFiles to true):

<core enableTracing="false" ...>
     <js defaultMinifier="EdwardsJsMinifier" usePreMinifiedFiles="true">
like image 137
muratgu Avatar answered Oct 25 '22 13:10

muratgu