Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 903
nixon Avatar asked Mar 14 '13 04:03

nixon


People also ask

What is CDN in MVC?

The optimization package in ASP.NET MVC framework has built-in support for Content Delivery Network (CDN). Using CDN can improve the performance of your application. The trick is to use it for popular libraries where the chances are that those libraries may have been cached by user's browser.

Can you explain MVC bundling?

Bundling and Minification are two performance improvement techniques that improves the request load time of the application. Most of the current major browsers limit the number of simultaneous connections per hostname to six. It means that at a time, all the additional requests will be queued by the browser.

What is a script bundle?

The ScriptBundle class represents a bundle that does JavaScript minification and bundling. You can create style or script bundles in BundleConfig class under App_Start folder in an ASP.NET MVC project.


1 Answers

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

like image 57
imran_ku07 Avatar answered Sep 27 '22 20:09

imran_ku07