1

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

6
  • What protocol are you using to access the page? Commented Mar 23, 2012 at 10:13
  • FWIW, the CDN does support http and https responses on that host and path. Commented Mar 23, 2012 at 10:32
  • 1
    Why are you using "//" instead of "/" for your relative path? Commented Mar 23, 2012 at 10:47
  • @austincheney — Because it is scheme-relative, not server-relative Commented Mar 23, 2012 at 10:50
  • @Quentin What is the difference? Commented Mar 23, 2012 at 10:51

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.