instructional systems
Index:
[Session8]URI and server: SCP, FTP
1 Chapter1
2 Chapter2
3 Chapter3
4 Chapter4
Your Location: Home Page  >  [2] HTML and CSS (on condition)  >  [Session8]URI and server: SCP, FTP  >  Chapter4  >  4.4 Absolute URI and Relative URI
Absolute URI and Relative URI
[The purpose of this section]
Learn what is relative URI and what are its characteristics, etc.

Which One Is More Useful, Absolute Reference or Relative Reference?

In relation to relative reference, aren’t you feeling as follows?

  • It is difficult to understand, because there are some abstract expression such as "./" and "../".
  • It is messy, because the reference name of the object file changes depending on the point-of-origin folder (folder you are looking at now).

I agree with you, because when you specify the file by absolute referencing it is straightforward and there is only one way to do that. However, since you have to input all the folders along the way starting from / (root directory) to the folder which stores the object file, the reference name could be very long. It is not easy. Imagine the situation where you have to input all the file names by absolute referencing. You wouldn't like it, would you?

By the way, when you do file operations, aren't you often saying "file xxxx which is located in the same folder as the file I am now editing", or "a file called yyyy"? If the way you say this is enough to specify a file, it means "you always looking at a certain folder and look at other files in a relative way using that folder as a reference point". In other words, in many cases, the relative reference is a more natural way of expressing things.

When you talk to other people, you usually say "the bakery in the town next to ours" or "the bakery in 9-chome". It would be strange if you always say "the bakery in 9-chome, Kurokami, Kumamoto city, Kumamoto prefecture, Japan". This is another example showing that in our day-to-day lives, we usually use relative ways of identifying things. Even in this way, we are still able to uniquely identify things etc. This is a lot more common way.

Moreover, if you use relative reference, in many cases you are just looking at a relatively small area around the folder you are looking at. As a result, even if the composition of the folders and files on the layers above is altered, you are less likely required to change the reference name.

Take the image below, for example (you have seen this image before a number of times), what happens to the reference name of the soft ice cream ex1.html if you change the folder name "w05" to "week05" and the name of the folder that contains soft ice cream ex1.html from "test" to "ice"?

仮想世界1

Whereas the relative reference seen from Kumataro is still "./ex1.html", the absolute reference changes from "/public_html/w05/test/ex1.html" to "/public_html/week05/ice/ex1.html".

This is one of the characteristics of relative reference; i.e., if you use relative reference notation, the notation will be less likely influenced by the change of folder composition etc. The reason for this is as follows:
Generally speaking, there are many folders on the WWW Server, and changes of folder name or changes of folder composition keep happening all the time, depending on the situation. When that happens, if the referencing file name is given in absolute reference in an HTML file, then you have to change all the relevant file names. You would not like to do such a thing, would you?

Therefore, you need to get used to relative reference. Then you do not have to do a lot of unnecessary work.

(Note) However, in these cases indicated below, absolute reference is more useful, so I am not saying that you have to use relative reference all the time.
  • Referencing to a file in a folder which is very far from the folder you are looking at now
    In this case, notation could be shorter when you use absolute reference.
  • The folder you should be looking at has not been specified yet.
    In such case, you tend to specify the folder you want to look at by absolute referencing first, after that you do other operations.

Absolute URI and Relative URI

So far in the discussion, absolute reference is explained to be as "a reliable identification method for which there is only one way of expression". However, come to think of it, this is only true within one WWW Server. If there is another WWW Server which has the same folder composition and stores the files which have exactly the same names, can you still identify the files over these two servers in a uniform way?

Yes, you can! All you have to do is, in addition to the absolute reference of the file, to specify the name of the WWW Server which you are looking at now (object).

Don't you think "Oh, I think I have come across this one before!"? Yes, this is the "URI". The URI is a notation to specify a resource (file) on the Internet, but actually it is no other than an expanded version of absolute reference. (However, the URI is expanded further to include the protocol, a typical example being http, which is a procedure to deal with the resources, isn't it?)

Here is the format of the URI again.

URI

Actually "the server part" represents the name of the (WWW) server, and "the path part" is the object file (resource) described in absolute reference system. You should now be able to understand that "/kiss/G/top.html" is absolute reference notation.

The URI is used when you input it directly in the address bar of the Web Browser or when you set up a link specifying it as an attribute value of href, an attribute of the a element in HTML. For example, URI is included as a value of href attribute of the a element in the format below.

 <a href="http://www.kumamoto-u.ac.jp/kiss/G/top.html"> The page for Kumamoto University students </a>

By the way, you are allowed to put the value of href attribute of the a element in the following manner:

 <a href="./top.html"> The page for Kumamoto University students </a>

For example, if the a element is written in an HTML file in /kiss/G (by absolute referencing) folder, the "./top.html" file by relative referencing becomes "/kiss/G/top.html" in absolute reference notation. In addition, if the HTML file containing the a element mentioned above is located at www.kumamoto-u.ac.jp, the notation "/top.html" indicates exactly the same thing (file/resource) as "http:// www.kumamoto-u.ac.jp/kiss/G/top.html" (assuming that we use http as a scheme).

In other words, a notation which simply specifies a file by relative referencing such as "./top.html" can function the same way as a URI if it is inserted in such a place that should have a URI as the value of href attribute. For this reason, the relative reference notation used for this purpose is called "relative URI". In contrast, the complete URI comprising the scheme, the server part, and the path part, which we just called URI so far, is sometimes called "absolute URI".

Previously, we specified a file in the following manner when we used the img element which inserts an image. Actually, this is another example of relative URI.

 <img src="./animation.gif" alt="アニメーション">

By the way, so far a relative reference has been explained as "a way of referencing files by indicating the relative location from the folder which you are looking at now". In this explanation, the folder which you are looking at now is supposed to be on a certain WWW Server. Then, is it possible to specify a resource (file) which is on a different WWW Server in the "relative URI" where you use relative reference system?

The answer is "No".
The "relative URI" can only indicate a file on the same server where the HTML file in which the relative URI in question is written is stored. The reason for this is that a relative URI assumes the WWW Server to be the server which stores the HTML file in which the relative URI in question is written. Otherwise, how can you omit the name of the WWW Server?
In other words, you are required to use the usual URI (absolute URI) to specify the resources on any other servers than the WWW Server where the HTML file in which the URI is written is stored.

However, as discussed in the section on absolute reference and relative reference, please try to use the relative URI as much as you can. In that way, you do not have to change the description regardless of whether the HTML file is on your PC or on the WWW Server. In addition, you are less likely to be in need of changing the URI description even if the directory structure is altered to a certain degree.

Copyright (C) Kenichi Sugitani 2005, All Rights Reserved