Relative Vs. Absolute
comments | Posted in job | thoughts | web on Monday, October 08 2007 22:14:00 GMT
This About.com Article expresses as clearly as I could have stated, my thoughts on paths in html code.
I was slightly ranted at today for placing: /css, /js and /images paths in my html [relative paths anchored to the webroot].
I see anyone using relative paths for everything as a lunatic >:)
Web sites have specific file-structure layouts, and are typically designed to be hosted at a particular url: http://www.mysite.com/ http://www.mysite.com/test/
An individual told me my site broke when he placed it under a /test directory for appraisal and testing. The site was destined to live within a web_root and not a subdirectory. A directory structure and url structure were assumed, and enforced ... of course it broke.
So Why Not Use Relative Paths to Solve this Problem?
The issues involved are maintainability and ambiguity. If I have 3 css files which use the file background.jpg. If I have:
- /theme1/background.jpg
- /theme2/background.jpg
- /theme3/background.jpg
I have to be exact as to which background.jpg file I use for which theme. This issue compounds itself when I have dozens of directories and themes! And more so when I have hundreds of HTML files.
HTML should explicitly state its dependencies. All the information I should need to know for maintaining the site should be on the page. No prior knowledge of the site's conventions need be known (are there multiple themes, and many similarly named files) to maintain the site.
I should be able to open up a file and point to a path and say:
Image /images/voodoo_child.jpg is missing and breaking the site.
VS.
Image ../../../images/voodoo_child.jpg is broken. Ok, I'm in france_trip20007/ so thats up to /europe and then up thru /travel and into the images directory.
Its just much easier to always work down from the root of the tree, instead of starting in some obscure middle of the forest location :P