Using CDN in MVC script bundle. What am I missing?

nixon picture nixon · Mar 14, 2013 · Viewed 65k times · Source

I am trying to use a CDN for loading jquery. I have read this article and this seems like it should be very straightforward.

My script bundle is defined as follows.

bundles.UseCdn = true;
bundles.Add(new ScriptBundle("~/bundles/jquery", "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js").Include(
                        "~/Scripts/jquery-{version}.js"));

I am including it on the page as follows:

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

    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>
</html>

But when I look at firebug it seems that jquery is being loaded from localhost. firebug inspection

I have tried with both realease and debug builds. What am I missing? I think this should be quite straightforward. Thanks.

Answer

imran_ku07 picture imran_ku07 · Mar 14, 2013

Run your application in debug="false" mode or use BundleTable.EnableOptimizations = true;