2

I've noticed that a lot of links to remote libraries are missing the http: from the src attribute: (this site uses it as well: that's where I got the example below)

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

Is there an advantage in linking to remote files in this way? I know this question will probably get flagged because it doesn't call for a specific coding response, but I've searched for an answer without a whole lot of luck, probably because I don't know how to refer to it correctly.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Realto619
  • 301
  • 3
  • 13
  • 3
    If you didn't know if the site was going to be used over http: or https:, this would allow the same `src` to be used for either and avoid mixed secure/insecure warnings. – Joe Jul 18 '13 at 23:10
  • 2
    It's a *"[protocol-relative URL](http://blog.niftysnippets.org/2011/01/skipping-protocol.html)*". On an `http:` page, it inherits the `http:` protocol. On an `https:` page, it inherits `https:`. This prevents the browser's warning about parts of the page being secured (`https:`) and other parts not being secured (`http:`). – T.J. Crowder Jul 18 '13 at 23:13
  • @Joe: Ah, that makes sense. Thank you for the lightning-fast response, sir. Much appreciated! – Realto619 Jul 18 '13 at 23:14
  • @T.J.Crowder: Thanks for the link and the proper way to address this methodology. – Realto619 Jul 18 '13 at 23:16

0 Answers0