Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double slash at beginning of javascript include

I have been looking at the html5 boilerplate and noticed that the jquery include url starts with a double slash. The url is //ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

Why is the http: missing?

like image 575
David Avatar asked Jun 14 '11 21:06

David


People also ask

What is the double slash in Javascript?

The double slash is a comment. Triple slash doesn't mean anything special, but it might be a comment that was added right before a division. Show activity on this post. Short answer: Those are just comments.

What starts with a double slash?

It means, that the link reference uses the same protocol (http: or https:) like the current page. If you call the page with http: the link goes to http: as well, if you call the page with https: the link has https too. This is most useful not only for links but for images, javascript and other external resources.

How do you add a double slash in Javascript?

you create a string in javascript by putting the string inside quotations: var answer = "It's alright"; var answer = "He is called 'Johnny'"; var answer = 'He is called "Johnny"'; Which you have correctly done.

What does double backslash do in Javascript?

Answer. When a string is double quoted, it is processed by the compiler and again at run-time. Since a backslash (\) is removed whenever the string is processed, the double-quoted string needs double backslashes so that there is one left in the string at run time to escape a "special character".


1 Answers

I hate answering with a link but this explains it - http://paulirish.com/2010/the-protocol-relative-url/


Using a protocol relative URL like "//mydomain/myresource" will ensure that the content will be served via the same scheme as the hosting page. It can make testing a bit more awkward if you ever use FILE:// and then some remote locations as they will obviously resolve back to FILE. Never the less it does resolve the mixed insecure/secure content messages you can cause by not using it.

like image 116
Mike Miller Avatar answered Sep 19 '22 05:09

Mike Miller