Skip to main content
Active reading. Dressed a naked link (the location also changed at Wikipedia).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

See this: http://en.wikipedia.org/wiki/URI_scheme#Generic_syntaxExample URIs (Wikipedia).

In a webapplicationweb application, I would advise to use relative URLs for all resources that belong to your app. That way, if you change the location of the pages, everything will continue to work. Any external resources (could be pages completely outside your application, but also static content that you deliver through a content delivery network) should always be pointed to using absolute URLs: if you don't there simply is no way to locate them, because they reside on a different server.

See this: http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax

In a webapplication, I would advise to use relative URLs for all resources that belong to your app. That way, if you change the location of the pages, everything will continue to work. Any external resources (could be pages completely outside your application, but also static content that you deliver through a content delivery network) should always be pointed to using absolute URLs: if you don't there simply is no way to locate them, because they reside on a different server.

See Example URIs (Wikipedia).

In a web application, I would advise to use relative URLs for all resources that belong to your app. That way, if you change the location of the pages, everything will continue to work. Any external resources (could be pages completely outside your application, but also static content that you deliver through a content delivery network) should always be pointed to using absolute URLs: if you don't there simply is no way to locate them, because they reside on a different server.

foo://username:[email protected]:8042/over/there/index.dtb;type=animal?name=ferret#nose \ / \________________/\_________/ \__/ \___/ \_/ \_________/ \_________/ \__/ | | | | | | | | | | userinfo hostname port | | parameter query fragment | \_______________________________/ \_____________|____|____________/ scheme  | | | | | authority |path| | | | | path interpretable as filename | ___________|____________ | / \ / \ | urn:example:animal:ferret:nose interpretable as extension 

An absolute urlURL includes the parts before the "path" part - in other words, it includes the scheme (the http in http://foo/bar/baz) and the hostname (the foo in http://foo/bar/baz) (and optionally port, userinfo and port).

Relative urlsURLs start with a path.

Absolute urlsURLs are, well, absolute: the location of the resource can be resolved looking only at the urlURL itself. A relative url isURL is in a sense incomplete: to resolve it, you need the scheme and hostname, and these are typically taken from the current context. For example, in a web page at

In the href attribute of the link, a relative url sURLs used, and if it is clicked, it has to be resolved in order to follow it. In this case, the current context is

(note the / appearing at the start of the urlURL) then it would have been resolved as

In a webapplication, I would advise to use relative urlsURLs for all resources that belong to your app. That way, if you change the location of the pages, everything will continue to work. Any external resources (could be pages completely outside your application, but also static content that you deliver through a content delivery network) should always be pointed to using absolute urlsURLs: if you don't there simply is no way to locate them, because they reside on a different server.

foo://username:[email protected]:8042/over/there/index.dtb;type=animal?name=ferret#nose \ / \________________/\_________/ \__/ \___/ \_/ \_________/ \_________/ \__/ | | | | | | | | | | userinfo hostname port | | parameter query fragment | \_______________________________/ \_____________|____|____________/ scheme  | | | | | authority |path| | | | | path interpretable as filename | ___________|____________ | / \ / \ | urn:example:animal:ferret:nose interpretable as extension 

An absolute url includes the parts before the "path" part - in other words, it includes the scheme (the http in http://foo/bar/baz) and the hostname (the foo in http://foo/bar/baz) (and optionally port, userinfo and port).

Relative urls start with a path.

Absolute urls are, well, absolute: the location of the resource can be resolved looking only at the url itself. A relative url is in a sense incomplete: to resolve it, you need the scheme and hostname, and these are typically taken from the current context. For example, in a web page at

In the href attribute of the link, a relative url s used, and if it is clicked, it has to be resolved in order to follow it. In this case, the current context is

(note the / appearing at the start of the url) then it would have been resolved as

In a webapplication, I would advise to use relative urls for all resources that belong to your app. That way, if you change the location of the pages, everything will continue to work. Any external resources (could be pages completely outside your application, but also static content that you deliver through a content delivery network) should always be pointed to using absolute urls: if you don't there simply is no way to locate them, because they reside on a different server.

foo://username:[email protected]:8042/over/there/index.dtb;type=animal?name=ferret#nose \ / \________________/\_________/ \__/ \___/ \_/ \_________/ \_________/ \__/ | | | | | | | | | | userinfo hostname port | | parameter query fragment | \_______________________________/ \_____________|____|____________/ scheme | | | | | authority |path| | | | | path interpretable as filename | ___________|____________ | / \ / \ | urn:example:animal:ferret:nose interpretable as extension 

An absolute URL includes the parts before the "path" part - in other words, it includes the scheme (the http in http://foo/bar/baz) and the hostname (the foo in http://foo/bar/baz) (and optionally port, userinfo and port).

Relative URLs start with a path.

Absolute URLs are, well, absolute: the location of the resource can be resolved looking only at the URL itself. A relative URL is in a sense incomplete: to resolve it, you need the scheme and hostname, and these are typically taken from the current context. For example, in a web page at

In the href attribute of the link, a relative URLs used, and if it is clicked, it has to be resolved in order to follow it. In this case, the current context is

(note the / appearing at the start of the URL) then it would have been resolved as

In a webapplication, I would advise to use relative URLs for all resources that belong to your app. That way, if you change the location of the pages, everything will continue to work. Any external resources (could be pages completely outside your application, but also static content that you deliver through a content delivery network) should always be pointed to using absolute URLs: if you don't there simply is no way to locate them, because they reside on a different server.

Formatting change: I wanted to make sure the important code lines would be clearly visibile.
Source Link

Absolute urls are, well, absolute: the location of the resource can be resolved looking only at the url itself. A relative url is in a sense incomplete: to resolve it, you need the scheme and hostname, and these are typically taken from the current context. For example, in a web page at http://myhost/mypath/myresource1.html,

http://myhost/mypath/myresource1.html 

you could put a link like so <a href="pages/page1">click me</a>.

<a href="pages/page1">click me</a> 

In the href attribute of the link, a relative url s used, and if it is clicked, it has to be resolved in order to follow it. In this case, the current context is http://myhost/mypath/myresource1.html,

http://myhost/mypath/myresource1.html 

so the schema, hostname, and leading path of these are taken and prepended tto pages/page1, yielding http://myhost/mypath/pages/page1.

http://myhost/mypath/pages/page1 

If the link would have been: <a href="/pages/page1">click me</a>

<a href="/pages/page1">click me</a> 

(note the / appearing at the start of the url) then it would have been resolved as http://myhost/pages/page1,

http://myhost/pages/page1 

because the leading / indicates the root of the host.

Absolute urls are, well, absolute: the location of the resource can be resolved looking only at the url itself. A relative url is in a sense incomplete: to resolve it, you need the scheme and hostname, and these are typically taken from the current context. For example, in a web page at http://myhost/mypath/myresource1.html, you could put a link like so <a href="pages/page1">click me</a>. In the href attribute of the link, a relative url s used, and if it is clicked, it has to be resolved in order to follow it. In this case, the current context is http://myhost/mypath/myresource1.html, so the schema, hostname, and leading path of these are taken and prepended t pages/page1, yielding http://myhost/mypath/pages/page1. If the link would have been: <a href="/pages/page1">click me</a> (note the / appearing at the start of the url) then it would have been resolved as http://myhost/pages/page1, because the leading / indicates the root of the host.

Absolute urls are, well, absolute: the location of the resource can be resolved looking only at the url itself. A relative url is in a sense incomplete: to resolve it, you need the scheme and hostname, and these are typically taken from the current context. For example, in a web page at

http://myhost/mypath/myresource1.html 

you could put a link like so

<a href="pages/page1">click me</a> 

In the href attribute of the link, a relative url s used, and if it is clicked, it has to be resolved in order to follow it. In this case, the current context is

http://myhost/mypath/myresource1.html 

so the schema, hostname, and leading path of these are taken and prepended to pages/page1, yielding

http://myhost/mypath/pages/page1 

If the link would have been:

<a href="/pages/page1">click me</a> 

(note the / appearing at the start of the url) then it would have been resolved as

http://myhost/pages/page1 

because the leading / indicates the root of the host.

Source Link
Roland Bouman
  • 32.1k
  • 8
  • 69
  • 69
Loading