Bundle script file not being rendered.
Asked Answered
P

7

30

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?

Permanent answered 16/1, 2013 at 18:58 Comment(0)
G
52

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.

Gossoon answered 16/1, 2013 at 20:36 Comment(4)
cannot believe that ASP.NET use that trick. No error, just fail silently!!Pettit
Also, if the bundle virtual path contains a dot, it would work during development but not working for published site. bundles.Add(new ScriptBundle("~/Scripts/jquery.validate").Include("~/../Scripts/jquery.validate.*"));Stunk
This solved my problem. No clues anywhere, it just didn't include the script! I remoev .min and all goodRudimentary
But why did Microsoft decide to ignore bundling min-files?Kkt
A
17

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.

Alysiaalyson answered 16/1, 2013 at 21:8 Comment(0)
S
7

I had to do this in Application_Start:

BundleTable.EnableOptimizations = true;
Seyler answered 10/3, 2014 at 17:42 Comment(0)
R
3

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.

Refrigerant answered 9/2, 2017 at 11:38 Comment(0)
P
2

If none of the above questions resolve your problem maybe you're missing this line

BundleConfig.RegisterBundles(BundleTable.Bundles);

from the Global.asax.cs file, if you're getting started with bundling take a look of this site: https://www.asp.net/mvc/overview/performance/bundling-and-minification

Portia answered 19/10, 2016 at 0:24 Comment(0)
L
0

In my case Visual Studio 2013 just thought that bundling css files are missing, it showed yellow question mark over the filename in Solution Explorer.

Just double-click all these supposedly missing files and Visual Studio will find them, yellow question will mark dismiss and bundling will start working again like a charm.

Luxuriant answered 8/7, 2016 at 13:32 Comment(0)
T
-1

and make sure you're not using IE 8. Bundling failed for me in that browser but works fine in Chrome or Firefox.

Tuberose answered 2/2, 2015 at 21:49 Comment(1)
bundles are created at server side, so browser should not make differenceBarouche

© 2022 - 2024 — McMap. All rights reserved.