Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute URLs omitting the protocol (scheme) in order to preserve the one of the current page

I saw the //somepage.com/resource url format. For example:

<img src="//remotesite.com/image1.jpg" /> 

The point of this is that if the current page (the page defining the img tag) is using http, then the request to the remote site is made via http. If it is https - it's https. This eliminates browser warnings of not fully encrypted pages.

My question is - is this URL format safe to use for all browsers. And is it a standard?

like image 587
Bozho Avatar asked Feb 12 '11 13:02

Bozho


People also ask

What is the absolute URL for a Web page?

An absolute URL is the full URL, including protocol ( http / https ), the optional subdomain (e.g. www ), domain ( example.com ), and path (which includes the directory and slug). Absolute URLs provide all the available information to find the location of a page.

How do you make an absolute URL?

If you prefix the URL with // it will be treated as an absolute one. For example: <a href="//google.com">Google</a> . Keep in mind this will use the same protocol the page is being served with (e.g. if your page's URL is https://path/to/page the resulting URL will be https://google.com ).

What does absolute URI mean?

Absolute URI is defined in RFC 3986. Some protocol elements allow only the absolute form of a URI without a URI Fragment Identifier. For example, defining a base URI for later use by relative references calls for an absolute-URI syntax rule that does not allow a fragment.


1 Answers

is this URL format safe to use for all browsers.

I can't say anything for sure, but you should be able to test it in different browsers.

And is it a standard?

Technically, it is called "network path reference" according to RFC 3986. Here is the scheme for it:

  relative-ref  = relative-part [ "?" query ] [ "#" fragment ]    relative-part = "//" authority path-abempty                 / path-absolute                 / path-noscheme                 / path-empty 

There is a problem though, when used on a <link> or @import, IE7 and IE8 download the file.

Here is a post written by Paul Irish on the subject:

  • The protocol-relative URL
like image 102
Sarfraz Avatar answered Sep 21 '22 14:09

Sarfraz