Re: Full versus relative URLs
| From: | Johnny | Date: | Wed, 18 Feb 2009 14:57:54 +0000 |
| Subject: | Re: Full versus relative URLs | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288536@lists.php.net to get a copy of this message | ||
Thodoris a écrit :
Hi Thodoris, In my opinion, the best use is to include your file with relative urls, like : <img src="/path/to/img.jpg" /> for "client side files" (file from browsers. For includes serverside, i usually use $_SERVER['DOCUMENT_ROOT'] "root path" for inclusion, like : require_once($_SERVER['DOCUMENT_ROOT'] . '/../init/init.base.inc'); regards, JokoHere's a question related to my last post. When specifying a link in a HTML file (like to the css or an image file), there are two ways of doing it. One is to simply include the relative path to the file (relative to the doc root), like: /graphics/my_portrait.gif Or you can include the full URL, like: http://example.com/graphics/my_portrait.gif My casual observation seems to indicate that the former will load faster than the latter. But has anyone done any benchmarking on it? PaulI am not aware if absolute URLs are faster or not (in case they are there will be such a small difference you cannot probably notice) but IMHO it is a bad practice to use full URLs. Basically because renaming directories or scripts will cause great pain in the ass. Of course resources that are coming outside your own site are needed to use absolute URLs and nobody is assuming that are useless.