1

I don't remember when I started seeing URLs without the protocols.

<script src="//jquery.com/jquery.js"></script>

... but I immediately understood. It's great not to have to list the protocol when we don't know what it will be. Unfortunately I don't know what the rules are here.

Is this okay too?

<link href="//stylesheet.com/stylesheet.css" />

What about this?

/* stylesheet.css */
@import url(//fonts.googleapis.com/css?family=Questrial);

I'm not just looking for the answers here, but where to look to read the definitive guide. And I don't even know what this technique is called.

I don't know what the browser support is or what would happen in a case where the browser didn't support it.

Thanks for the help!

Update

A lot of the answers I was looking for are found on this question.

Community
  • 1
  • 1
rb-
  • 2,315
  • 29
  • 41
  • Just as you can write `/path/from/root.css`, you can write `//example.com/url/relative/to/protocol`. It's just a relative link. – Niet the Dark Absol Dec 30 '14 at 20:59
  • 1
    "scheme-less URL" is the keyword you want. http://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just Not sure there is a definitive guide anywhere. – loganfsmyth Dec 30 '14 at 21:00

1 Answers1

2

These are called protocol-relative URIs.

The resolution rules are described in RFC 3986.

4.2. Relative Reference

A relative reference takes advantage of the hierarchical syntax (Section 1.2.3) to express a URI reference relative to the name space of another hierarchical URI.

  relative-ref  = relative-part [ "?" query ] [ "#" fragment ]

  relative-part = "//" authority path-abempty
                / path-absolute
                / path-noscheme
                / path-empty

Section 5.4 has examples.

5.4. Reference Resolution Examples

Within a representation with a well defined base URI of

  http://a/b/c/d;p?q

a relative reference is transformed to its target URI as follows.

  ...
  "//g"           =  "http://g"
  ...
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245