Calluna
Calluna

Reputation: 31

Can't load javascript using CDN

When I try to load Javascript files using CDN it doesn't work. I get status "Abort"

This is what my code look like (using ASP.Net MVC 3):

<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/jquery-ui-1.8.11.min.js") %>" type="text/javascript"></script>

This is what Firebug says:

Firebug info When I right click the GET jquery-1.7.1.min.js and selects "Copy location" it returns http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.1.min.js which is perfectly valid

// Martin

Upvotes: 1

Views: 1069

Answers (1)

RickAndMSFT
RickAndMSFT

Reputation: 22770

If you're going through a proxy/server, the CDN might think it's a DOS attack. Try the GOOG CDN. See my blog http://blogs.msdn.com/b/rickandy/archive/2011/05/21/using-cdns-to-improve-web-site-performance.aspx

Let me know if you'd like me to send you the project. BTW, you should never depend on the CDN, you need to verify the file was loaded - and if not, download it from your site. Use something like the following:

<script type="text/javascript">if (typeof jQuery == 'undefined') {  
var e = document.createElement('script');  
 e.src = '@Url.Content("~/Scripts/jquery-1.7.1.js")';  
e.type='text/javascript';   
document.getElementsByTagName("head")[0].appendChild(e);  
 }</script>

Upvotes: 2

Related Questions