0

Built a site in MVC, including jQuery in the layout file like this:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title</title>
    @Scripts.Render("~/bundles/jquery")
    @Styles.Render("~/Content/css")
</head>
<body>
    <!-- content -->
</body>
</html>

JQuery is referenced via nuget and bundled like this:

public class BundleConfig
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/jquery-ui.min.js",
            "~/Scripts/stickyfill.js"));
}

And that works fine running the site locally in Visual Studio.

When I deploy to IIS and try to run the site I get the dreaded Uncaught ReferenceError: jQuery is not defined error.

The first thing I checked was that the jQuery package was available via the address the deployed page was trying to use:

/bundles/jquery?v=[a token]

Which it is. You can even see it referenced in the bundles from Chrome Developer tools. It may be worth noting that the css, which is deployed via the same mechanism with a token, works fine.

I've also worked my way down the answers to the question JQuery - $ is not defined and either eliminted or tried them, to no avail.

The only thing I can think of is that it's not loading before the initial call to jQuery(document).ready() - which is why I moved the bundle into the <head> tag. But that doesn't help, and I don't know what else I can do to slow or wait for page load.

What on earth else could this be?

EDIT: Somone asked for the head of the rendered page:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>[the title]</title>
    <script src="/bundles/jquery?v=[a token]"></script>
    <link href="/Content/css?v=[a token]" rel="stylesheet"/>
</head>
Community
  • 1
  • 1
Bob Tway
  • 8,793
  • 12
  • 72
  • 144

1 Answers1

1

try this :

public class BundleConfig
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
            "~/Scripts/jquery-1.8.2.min.js",
            "~/Scripts/jquery-ui.min.js",
            "~/Scripts/stickyfill.js"));
}
Wasif Shahjahan
  • 326
  • 1
  • 8