PDA

View Full Version : is this a bad idea ../../../myfile.gif



listerdl
Feb 29th, 2012, 05:17 PM
Does it have a negative effect on speed loading on my website to have images or files like css coming from ../../filename.gif or is it better to more direct link?

Thanks

Lerura
Feb 29th, 2012, 06:37 PM
Nope! not at all!

Whether to use relative or absolute URLs depends on the needs:

If the image always is located at the same directory relative to the document, then you can use ../../filename.gif.

If the document is always located in the same postion, on the same server or computer you can use /images/filename.gif
as there is no dots in front of the first slash, it means root-directory.

But if the images is located on a different server, you need to use http://www.example.com/filename.gif

There are cases where you can choose between all version.
e.g. for files on the same server that never changes neither position nor relation

listerdl
Mar 2nd, 2012, 09:37 PM
thanks mate

felgall
Mar 2nd, 2012, 10:44 PM
Using the absolute address is the one that can be less efficient - it can require a DNS lookup to locate the nameservers in order to do another lookup to determine the IP address to look up the hosting server in order to then do yet another lookup to find the folder that the domain points to.

gr33nman
Mar 3rd, 2012, 02:23 AM
Linking comes in multiple flavors: absolute, relative or web root (aka root-relative).
http://www.motive.co.nz/glossary/linking.php

If your image is being used by multiple pages from multiple directories, it may pay to use the web root.

For instance, if you have a file '/images/flowers/sunflower-banner.gif' and it is used by
files '/news/index.php', '/posts/2012/02/index.php' and '/bb/forum/index.php' in a footer or header, you would have to use three different addresses to display the sunflower-banner.gif: for news it would be '../images/flowers/sunflower-banner.gif', for posts, it would be '../../../images/flowers/sunflower-banner.gif' and for the forum it would be '../../images/flowers/sunflower-banner.gif'.

It's easier to use the web root for all three in an included header or footer.
'/images/flowers/sunflower-banner.gif'
That way all of them will be able to reach the same image regardless of position in the directory structure of your site. Web root is always http://mysite.com/images/flowers/sunflower-banner.gif minus 'http://mysite.com'.