Reputation: 5331
I have the following jQuery CDN fallback on a test page. I am testing locally with chrome and IE. The CDN is not loading. If I use the http://
in the CDN it loads, but if I remove it and just use //
This makes no sense to me. If the script doesn't load the conditional statement should load it locally, but it's not. If I replace the
document.write('<script src="/scripts/jquery-2.1.1.min.js"><\/script>')
with
document.write('undefined')
then I get the word undefined on the page after about 5 seconds. Am I not scaping properly? Here is my html page:
<!DOCTYPE html>
<html>
<head>
<title>jQuery</title>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<script>
(window.jQuery || document.write('<script src="/scripts/jquery-2.1.1.min.js">
<\/script>'));
</script>
<script>
$(document).ready(function() {
alert( "welcome" );
});
</script>
</body>
</html>
Upvotes: 0
Views: 1855
Reputation: 5413
You may be loading the page using the file://
protocol. The exact meaning of the //
protocol is "use the same protocol that I am using". If you are looking at file://C:/Users/Me/test.html
, then your //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
becomes the URI file://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
which is not a valid file path on your computer. If you want to test locally you need to either use the http://
protocol in the link or host the project on IIS or apache on your box.
Upvotes: 6