benbyford
benbyford

Reputation: 649

why are we using relative scheme // instead of http:// or https://?

I've been having lots of problems with this new trend. It's been included everywhere (e.g. htmlboilerplate / twitter widgets) yet even twitter itself doesn't like it... (see image, when trying its twitter card preview).

Is there more to this than meets the eye, as it seems this has been implemented by coders before its been utilized fully by browsers or is it a legacy html?

Upvotes: 3

Views: 96

Answers (1)

Marc B
Marc B

Reputation: 360872

Because many sites are offering both regular (http) and encrypted versions (https) and using sub-domains for various things like images. you'd have to produce two completely different versions of the site if you were embedding things like

<img src="http://images.example.com/kittens.jpg" />

and served that up on the https:// version of the site, even though it's the exact same content. No one likes getting SSL errors, especially since those tend to come up as "zomg you're being spoofed/hacked/defrauded" type warnings in browsers.

But if you have the protocol-relative version,

<img src="//images.example.com/kittens.jpg" />

it won't matter if you're accessing the site via http://, https://, or even ftp:// for that matter - the url will still work and use the appropriate protocol, and you only have to maintain one copy of the content.

Upvotes: 6

Related Questions