HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 6. USING EXTERNAL RESOURCES 64


6.5 Why Not Absolute?


Say we were writing instructions for installing a refrigerator. We might want
to say “put it in the kitchen.” But which kitchen?


Kitchen is relative to where we are. If I am standing at 123 Main Street,
Anywhere, USA, it would mean the kitchen on that same property.


If we have to be absolute, we would have to write “put it in the kitchen of
123 Main Street, Anywhere, USA”. And then the instructions would only
work for that one house in the world.


On top of that, it is a bit tedious when talking to humans to add those extra
layers of absoluteness.


Our absolute instructions are brittle, inflexible, and fragile. When we rewrite
them for a different house, we have to be careful to make all the necessary
corrections.


Webpages also refer to places and things. They use URLs to do it. We could
make all our URLs absolute. But they would be brittle and fragile as well.


Sometimes we want absolute addressing. But when possible, we want rela-
tive addressing.


Things change. URLs change. Today your company website might be ex-
ample.org, and next year it might be example.com.


Or you want to repurpose some work you did. And rather than go through
your whole website looking for example.org and replacing it with exam-
ple.com, you just wish it could be done once and for all.


6.6 Relative To Our Base


Our base is the webpage where we currently are. The other URL is the place
we want to link to or pull a picture from. Here is an example. (1) is our
base, where we are. (2) is what we want.


(1)http://example.com/abc/def/ghi/index.html


(2)http://example.com/abc/def/ghi/photo.jpg


The absolute way of talking about (2) would be this:


http://example.com/abc/def/ghi/photo.jpg

Free download pdf