Relative vs. absolute URLs

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Does it make a difference in terms of loading time, browser caching, etc. to
use absolute vs. relative URLs and image file names?  I am using a PHP
include to put my main navigation on many pages in many different folders,
and to do so I am forced to define pages within my site as well as images
absolutely (i.e. http://...).  Unless there is another solution I am not
aware of.

Standard disclaimer: sorry if I missed anything while googling, relevant
URLs appreciated, etc. etc.


Re: Relative vs. absolute URLs

Kyle James Matthews wrote:
Quoted text here. Click to load it

No, exept that absolute urls tend to be longer, ie. loading slower. If
you had 300baud modem, you might notice difference.

Quoted text here. Click to load it

There is. PHP is programming language, of course you can program
something to do make them relative. I don't think it is worth hasle
trough. Anyway, why not make them relative to domain root
(/ = http://foo.example/ when used in foo.example)

Lauri Raittila < <
I'm looking for work | Etsin työtä

Re: Relative vs. absolute URLs

Quoted text here. Click to load it

Usually that's refered to as an absolute path.

Absolute paths work well when you don't know what directory you may be in
(or don't care).

It's a matter of the site architecture, personal style and whether you need
to view these locally or in a different environment whether to use relative
or absolute paths.

Quoted text here. Click to load it

Re: Relative vs. absolute URLs

Quoted text here. Click to load it

are you saying you are doing an include like:
include " " ;

You don't need to do that. If you have lots of pages with the same
include just do it as a full path:


If i recall sometimes you might need something like
[SERVER_document_root] first (note that is _not_ correct syntax for

Anyway you don't have to make an external request to your own website
which is what you would be doing in the first example.

You can also use relative URLs like ../ or
../myincludes/filetoinclude.php but they can be a pain in the ass if
you have a lot of different files all over the place who's path to the
include will be different

If you are doing includes based on user input make sure you check what
people are including first and make a very tight set of criteria that
it must pass



Site Timeline