6

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.

1
  • Are you sure the files exists, and you point to their exact relative URL? Most issues like this, is because the file cannot be found. Commented Jul 15, 2013 at 9:45

2 Answers 2

14

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Blade. Seems you hit the nail on the head. All script refs are now being included correctly.
No problem, happened to me the first time I used bundling :)
THANK YOU! just spent several hours chasing my tail on this.... demo's tomorrow :|
2

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.