Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Network-Path Reference URI / Scheme relative URLs

Scheme relative URLs (network-path references) are something that I've just found out about - where you don't specify the scheme of a URL and it picks it up from the current context.

For example: <img src="//domain.com/img.png" /> will resolve to https://domain.com/img.png if the current scheme is HTTPS or http://domain.com/img.png if it is not.

This seems like a very easy way to resolve those pesky problems of calling an external script or image on an SSL page without bringing up the dreaded error that some content on a page is not secure.

The benefit seems obvious, but what I don't seem to be able to find is a huge amount of information on this and was wondering if anyone had any experience or references about scheme relative URLs (good or bad)?

Whilst I'm trying to discover if there are any browsers that this causes issues with (I've been successful with IE6-8, Chrome and Firefox), I'm also interested to find out if anyone has any experience using this in different languages. For example, would it work if you were to issue a Response.Redirect with a scheme relative URL in ASP?

like image 941
Jonathon Bolster Avatar asked Aug 27 '10 10:08

Jonathon Bolster


People also ask

What is a relative URI?

A relative URL is a URL that only includes the path. The path is everything that comes after the domain, including the directory and slug. Because relative URLs don't include the entire URL structure, it is assumed that when linking a relative URL, it uses the same protocol, subdomain and domain as the page it's on.

What is the difference between absolute URL and relative URL?

An absolute URL contains all the information necessary to locate a resource. A relative URL locates a resource using an absolute URL as a starting point. In effect, the "complete URL" of the target is specified by concatenating the absolute and relative URLs.

What is absolute URL example?

An absolute URL contains the entire address from the protocol (HTTPS) to the domain name (www.example.com) and includes the location within your website in your folder system (/foldernameA or /foldernameB) names within the URL. Basically, it's the full URL of the page that you link to.


1 Answers

//domain.com/img.png is a perfectly valid URI syntax as per RFC 3986: Section 4.2.

It is relative to the current scheme, and therefore as you mentioned, it can be very useful when switching between http and https, because you won't need to explicitly specify the scheme.

All modern browsers will understand that format, including IE 6.

Further reading on Stack Overflow:

  • Is it valid to replace http:// with // in a <script src="http://...">?
  • Using // in a <script>'s source
like image 189
Daniel Vassallo Avatar answered Oct 25 '22 06:10

Daniel Vassallo