Relative path or url for html src and href attributes Relative path or url for html src and href attributes codeigniter codeigniter

Relative path or url for html src and href attributes


As far as DNS goes, it really doesn't matter if you have relative or absolute URL. Your browser ends up pre-pending the server URI onto the front anyway. Also, your network stack does the lookup for the first time, and caches the IP. Unless something goes wrong, there should only be the one lookup per page. YMMV of course, but that should be how this all works.


'Never' (alsmost never) use absolute paths.

It will bite you in the ass later.

For example when you switch / add another domain.

Go from your test to production server.

Basically the rule is internal URL's should be relative.


Oh you really don't want to use a full path. You'll have a lot of work ahead of you:

  • If you want to develop the site locally
  • You change / add domains (development, staging, etc)
  • You switch to using a CDN

You also will break your dev environment, since most modern ones will perform local directory lookups. Can't do that with a domain.

Also, in a dev environment you will be pulling from the production site, which will make modifying and adding images extremely tricky.

Most importantly, other developers working with your code will try to kill you. And that's bad for your health.