3

I'm writing a web crawler and I'm testing it out by starting at Wikipedia. However, I noticed that many of wikipedia's links are prefaced with //, so the link from wikipedia.org to en.wikipedia.org is a link to //en.wikipedia.org. What exactly does this // mean in practice? Does it say "use whatever scheme you were using before and then redirect to this url?" or does it mean something entirely different?

Jonathan
  • 3,369
  • 4
  • 22
  • 27
  • 1
    Yes, it is used to automatically handle sites that support boths http and https. It will maintain the current protocol. – Gabriele Petrioli Oct 12 '13 at 13:37
  • possible duplicate of [Is there any downside for using a leading double slash to inherit the protocol in a URL? i.e. src="//domain.com"](http://stackoverflow.com/questions/4659345/is-there-any-downside-for-using-a-leading-double-slash-to-inherit-the-protocol-i) – leesei Oct 12 '13 at 14:39
  • possible duplicate of [Two forward slashes in a url/src/href attribute](http://stackoverflow.com/questions/9646407/two-forward-slashes-in-a-url-src-href-attribute) – vzwick Feb 03 '14 at 15:04

4 Answers4

4

The link will use protocol (http or https) same as page which contain that link. For example if https://stackoverflow.com/ contain <a href="//en.wikipedia.org"></a> it will directed to https://en.wikipedia.org

iPao
  • 1,138
  • 17
  • 20
2

It maintains the protocol that is being used for the webpage. HTTP/HTTPS.

It's particulaly useful for external scripts and css tags, in which you don't know in which protocol your site will be working on.

That's why on Google libraries (https://developers.google.com/speed/libraries/devguide#jquery) you have like this:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Just while writing this I found a duplicate: Two forward slashes in a url/src/href attribute

Take a look at it.

Community
  • 1
  • 1
digao_mb
  • 1,294
  • 16
  • 23
  • 1
    And here is the major pitfall for local development.. when viewing an html page from you hard disk (*loaded with file://*) it will fail to load remote scripts due to it being translated to file://ajax.googleapis.com/... – Gabriele Petrioli Oct 12 '13 at 13:43
  • Good observation. I never had thought about it. – digao_mb Oct 12 '13 at 13:45
1

Yes, it will redirect to that url using the scheme of the current location.

In order for this to work, the resource this url points to must be available in every scheme it's expected to be redirected from (usually, both http and https).

geomagas
  • 3,230
  • 1
  • 17
  • 27
1

It is protocoll relative url. It keeps http or https.

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56