5

When I use the below Bundling in MVC 4, my App gets several JavaScript errors,such as 'jQuery undefined'

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

But when I use the below approach, my App works without JavaScript errors:

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

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

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

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

My Question: what is the problem?

JK.
  • 21,477
  • 35
  • 135
  • 214
user197508
  • 1,282
  • 2
  • 18
  • 31
  • In debug mode, are the individual script tags added in the correct order? – jrummell Mar 15 '13 at 14:24
  • 2
    Sounds like the scripts are being included in the wrong order. This answer suggests it might be the version of the Web Optimization Framework that you're using: http://stackoverflow.com/a/11995916/1043198 – Ant P Mar 15 '13 at 14:29
  • @AntP very thanks, i updated to Microsoft.AspNet.Web.Optimization version 1.1.0-Beta1 now my app works correctly. – user197508 Mar 15 '13 at 15:27
  • @user197508 I've posted my response as an answer :) – Ant P Mar 15 '13 at 15:30
  • @AntP thanks;) i accepted your answer with +1 vote. – user197508 Mar 15 '13 at 15:49

2 Answers2

3

This is caused by your scripts being included in the wrong order. You should ensure that your version of the Web Optimization Framework is up-to-date. This answer provides further details:

https://stackoverflow.com/a/11995916/1043198

And the NuGet package:

http://nuget.org/packages/Microsoft.AspNet.Web.Optimization

Community
  • 1
  • 1
Ant P
  • 24,820
  • 5
  • 68
  • 105
2

Solution:

I updated Microsoft.AspNet.Web.Optimization from version 1.0.0 to version 1.1.0-Beta1 now my app works correctly.

user197508
  • 1,282
  • 2
  • 18
  • 31