Swifty
Swifty

Reputation: 1432

MVC 4 BundleConfig not creating script references

I'm adding a few jQuery script files to my app 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 run my app and check the page source, 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 would this be happening? I can work around the issue by manually adding the script references directly to _Layout.cshtml, but that is hardly best practice.

Upvotes: 6

Views: 7417

Answers (2)

Oleksii Aza
Oleksii Aza

Reputation: 5398

It could be so because you didn't enable bundling. Try to change debug attribute value on compilation to false

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

Or enable it manually:

BundleTable.EnableOptimizations = true;

Upvotes: 2

CodingIntrigue
CodingIntrigue

Reputation: 78595

The .min part is already handled by MVC - it will automatically include .js files for Debug mode and .min.js files for Release mode.

Just download the unminified version of jquery.mCustomScrollbar.min.js and put it in your scripts directory, then reference 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"));

MVC will then load the appropriate script for Debug/Release

Upvotes: 14

Related Questions