shorthand http:// as // for script and link tags? anyone see / use this before?
Asked Answered
S

2

10

the question is as follows:

if you take a look at any site using addthis (the share button)...

once you float over the addthis button, and all of the required assets load take a look at the body of the document using firebug or chrome inspector (not the source, the actual document that is sitting on your screen... the object inspector). you will notice that the additional assets loaded automatically by addthis look something like this:

<script type="text/javascript" src="//s7.addthis.com/static/r07/menu78.js"></script>
<link rel="stylesheet" type="text/css" href="//s7.addthis.com/static/r07/widget61.css" media="all">

what is this short handing of http:// in the above tags?

has anyone used this before? does it have an 'official' name? how cross browser compatible is this method of short handing the http protocal?

yes, i understand this will break things as far as crawlers / seo go, but i am thinking about starting to use this in situations that are inaccessible (mainly, js handled stuff) to bots.

good or bad idea?

Syllable answered 28/6, 2011 at 8:52 Comment(2)
See this question for more info: #550538 as they refer to the relevant part in the RFC 3986 (Section 4.2 and 5.2.2). Also they should be refered to as Scheme-less (or a network-path reference) not Protocol-less.Presignify
to those that go in head over heals changing as much as possible to these shorthand links... there are multiple bugs in (of course) ie... one explained here (ie7/8+hash links): php5.skauti-pardubice.cz/IE7-missing-scheme-bug.php | other discussed in #550538Syllable
O
33

Starting a URL with // means "Use a different server but keep the same scheme"

So if you load //example.net/script from https://example.com/ it will get https://example.net/script, while if you load it from http://example.com/ it will get http://example.net/script.

If, on the other hand, you load it from file://c:/Users/You/Documents/test.html then it will probably not resolve to anything useful. Make sure you do development with a local web server (and access http://localhost/) if you use this syntax.

This is a standard part of URIs, it well supported, and is usually known as "scheme relative URIs"

Ottie answered 28/6, 2011 at 8:53 Comment(2)
I know I'm being a little pedantic here, but even if you specify https : //example.net and http : //example.net you are still using the same protocol: the http protocol. You are just using a different uri scheme.Presignify
searthing for this comment . Thank youGoodnight
S
5

To build upon Quentin's answer, these URLs are commonly called protocol-less URLs (although, as Nick points out in the comments, the proper name is scheme-less).

Also, be wary of the case where you use them in local development (i.e. linking to jQuery from an HTML page that you load from your hard disk, through the file:// protocol). In such scenarios, all outbound links will be treated as local ones - //jquery.com/ will refer to file://jquery.com/

Study answered 28/6, 2011 at 8:59 Comment(2)
Not the proper name. They should be referred to as scheme-less or network-path references. Cite: tools.ietf.org/html/rfc3986Presignify
I thought these were called "Protocol Relative URL"Phrygian

© 2022 - 2024 — McMap. All rights reserved.