Search code examples
includeinclude-path

Which way is better to use include - local address or remote url?


When I include php, css, graphic files etc., I tend to prefer using a local address, as this is easier to work with on local development (eg '../gfx/logo.png').

Nevertheless, this can cause problems if the file that triggers the include request is loaded from different location. At that case a local address include won't work, and therefore in these kind of files I use remote url address (eg 'http://site.com/gfx/logo.png').

A disadvantage of using a full path ('/root/mysite/gfx/logo.png') being on a shared server, this path is a bit long, and repeating it for every include is kind of messing the code.

Which is the most efficient, elegant way?


Solution

  • you can try the '<%=VirtualPathUtility.ToAbsolute("~/gfx/logo.png") %>' This helps me to test everything on my localhost as-well-as my QA server without worrying about changing the urls. hope it helps