Categories
Web Development

What browsers do when we ../ too much

Part of my thesis work touches on the way web browsers behave and how they process the code that the almighty developers throw at them. Most browsers do not scoff at crappy code, they do try to make sense of it and try to put lipstick on a pig. While testing my code on my own family website, I noticed an interesting behavior: the PHP header file I was including in all pages, had a reference to an image

<img src="../images/imageName.jpg" />


This should work in any subdirectory – where ../ means everywhere except the home page: the “../” in the beginning of the src reference tells the browser to go one directory up and then go down to the images directory where the image is stored. On the home page, this should not work, as there is *no directory above* the root directory, where the home page resides.

Still, browsers DO display that image, despite the moronic code (mine!). In other words, when a browser reaches the root directory and a reference is made to a directory above, it will ignore that reference and try to descend to subdirectories under it. I tested this with multiple ../ referencing directories above the root and still, the browsers prevailed.

Therefore, appreciate thy browser (just a bit)… Thank you browser!

Share

Leave a Reply

Your email address will not be published.

 

Share