Relative URL HTML/ XHTML Code Smell

Another one for the HTML/ XHTML Code Smells: If you’re using realtive URLs inside your documents (which is pretty valid and can save you some bandwidth as well as it can save some hassles for mirroring a website) you should not let them start with “./”. Even though it is totally valid according to RFC 3986, some user agents had problems to properly handle those URLs in the past. Looks like some implementations of the path combination in such a relative way. Example of a faulty path combination:

base:   /directory/index.html
embed:  ./dotexample.html
result: /directory./dotexample.html

An RFC 1808 / RFC 3986 conform UA would resolve relative URLs properly and would not run into this problem. Since there is most often a way to relativly link those files that even save two bytes, you should consider to better take care to not let them start with "./". The fix is to just not use it, so a plain "" does the job:

base:   /directory/index.html
embed:  nice.html
result: /directory/nice.html

Take care. Some browsers even made kind of more esoteric moves here when using dots.

This entry was posted in Code Smells, Hakre's Tips, HTML/CSS Code Smells, Patched, Pressed and tagged , , , , , , , , . Bookmark the permalink.

1 Response to Relative URL HTML/ XHTML Code Smell

  1. Pingback: Relative URL (#2) HTML/ XHTML Code Smell « hakre on wordpress

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.