0

Possible Duplicate:
Is it valid to replace with // in a <script src=“…”>?

I've been seeing sites linking to CSS and JS without the protocol more and more often lately:

<script src="//domain.cloudfront.net/file.js" type="text/javascript"></script>

And CSS

<link href="//domain.cloudfront.net/styles.css" media="screen" rel="stylesheet" type="text/css" />

Is this valid in all browsers? Does leaving off http or https mean the browser intelligently decides which protocol to use?

Community
  • 1
  • 1
Justin
  • 42,716
  • 77
  • 201
  • 296
  • Also a duplicate of [this](http://stackoverflow.com/questions/7693598/using-instead-of-protocol), [this](http://stackoverflow.com/questions/4978235/absolute-urls-omitting-the-protocol-scheme-in-order-to-preserve-the-one-of-the), [this](http://stackoverflow.com/questions/5799577/does-using-www-example-com-in-javascript-chose-http-https-protocol-automatical), [this](http://stackoverflow.com/questions/6503946/shorthand-http-as-for-script-and-link-tags-anyone-see-use-this-before) and probably more than a few others. – Quentin May 09 '12 at 06:27

1 Answers1

2

Yup. Paul Irish has a good blog entry about this. http://paulirish.com/2010/the-protocol-relative-url/

It's basic purpose is to prevent those IE pop ups that warn you that some of the resources on the page are "non-secure" when your main protocol is https but you grab something with http.

Miles
  • 1,615
  • 4
  • 17
  • 42
  • 2
    I'd hope that people use it so that they don't introduce security problems rather then to prevent browsers warning their visitors about those security problems! – Quentin May 09 '12 at 06:30
  • Ha, true. That's an epically long debate reserved for quora or something. – Miles May 09 '12 at 06:33
  • Apparently it causes IE 7/8 to [double-download CSS files](http://stackoverflow.com/a/2975722/283366) – Phil May 09 '12 at 06:34