Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle script file not being rendered.

Script file name:

jquery.transit.min.js

The file is in the Scripts folder,

bundles.Add(new ScriptBundle("~/bundles/jquery")
       .Include("~/Scripts/jquery-{version}.js"));

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

bundles.Add(new ScriptBundle("~/bundles/jqueryval")
       .Include("~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate*"));

bundles.Add(new ScriptBundle("~/bundles/jtransit")
       .Include("~/Scripts/jquery.transit*"));

In my View,

@Scripts.Render("~/bundles/jquery","~/bundles/jtransit")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/jqueryval")

Rendered HTML

<script src="/Scripts/jquery-1.8.3.js"></script>
<script src="/Scripts/jquery-ui-1.9.2.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

jquery.transit.min.js doesn't get rendered. What am I missing?

like image 805
Bilal Fazlani Avatar asked Jan 16 '13 18:01

Bilal Fazlani


4 Answers

I think it will be because you only have the .min version of your file.

From your output I can see that you are running the debug build of your site. I guess as such the bundler is looking for a non-minified file.

If you were to do a Release build, then it would be bundled in OK.

I'd suggest getting a non-minified version of the transit file and including that in your Scripts folder. Failing that, just make a copy of the minified version but without the .min in the filename.

like image 200
ngm Avatar answered Nov 05 '22 11:11

ngm


Starting in MVC4, any minimized version of your JavaScript files or CSS files are ignored in Debug mode. As ngm suggests, you need to rename your file from,

jquery.transit.min.js

to,

jquery.transit.js

Alternatively, you could modified the bundles.IgnoreList to allow minimized files to be rendered, as shown here.

like image 36
rae1 Avatar answered Nov 05 '22 11:11

rae1


I had to do this in Application_Start:

BundleTable.EnableOptimizations = true;
like image 7
Daniel Avatar answered Nov 05 '22 11:11

Daniel


In my case, I was attempting to use a script bundle and a style bundle with the same name.

BundleConfig.cs:

bundles.Add(new ScriptBundle("~/bundles/custom")
    .Include("~/Scripts/custom.js"));

bundles.Add(new StyleBundle("~/bundles/custom")
    .Include("~/CSS/custom.css"));

_Layout.cshtml:

@Scripts.Render("~/bundles/custom")
@Styles.Render("~/bundles/custom")

This doesn't work. The last bundle added in the config survives, and @Scripts.Render("~/bundles/custom") just renders an empty line.

I am using MVC 5.2.3.

like image 3
R. Schreurs Avatar answered Nov 05 '22 12:11

R. Schreurs