Jump to content

Yes to Full Path or No?


fize4ever

Recommended Posts

Hey all, just me passing by with another topic :)

 

In CSS, is it preferred to write the full image path all the way from the "http" to the image format (such as png, gif, etc), or should we shortcut it to the directory that contain the images like this: "/images/filename.format"

So what's preferred and what isn't?

Thanks in advance to everyone who took the time to read this topic :)

Also, thank you Killersites for always helping me out, I must be such a burden :lol:

Link to comment
Share on other sites

I prefer full paths.

 

The savings for the server are minimal and the path is always right!

 

Clearly you want one central place to work out of, that is the idea of CSS. But what if you have sub sections? Or you retire the design but want it archived?

 

Specific for your question, yea relative would be ok, just consider this in other cases:

You have a css that points your index page to the images it needs in an image folder, so images/image.jpg. Top level to folder.

 

Now lets say you use PHP includes and break up your file into specified folders for file clarity. Now a file is in a folder called HTML. The path to the same image would be ../images/image.jpg. You should have your includes using their own folder, again it would be ../images/image.jpg

 

If your css path is images/image.jpg then the file and include will have a broken link, if ../images/image.jpg then the index page will have a broken link. You could define it by a class, each class path uses a different path... or you use a fully qualified path complete with HTTP: etc.. Then it does not matter where the files are in the structure, the path will always lead direct to the image.

 

I had that issue with includes and since then I always use full paths, it is safer and lest apt to break.

Link to comment
Share on other sites

I prefer full paths.

 

The savings for the server are minimal and the path is always right!

 

Clearly you want one central place to work out of, that is the idea of CSS. But what if you have sub sections? Or you retire the design but want it archived?

 

Specific for your question, yea relative would be ok, just consider this in other cases:

You have a css that points your index page to the images it needs in an image folder, so images/image.jpg. Top level to folder.

 

Now lets say you use PHP includes and break up your file into specified folders for file clarity. Now a file is in a folder called HTML. The path to the same image would be ../images/image.jpg. You should have your includes using their own folder, again it would be ../images/image.jpg

 

If your css path is images/image.jpg then the file and include will have a broken link, if ../images/image.jpg then the index page will have a broken link. You could define it by a class, each class path uses a different path... or you use a fully qualified path complete with HTTP: etc.. Then it does not matter where the files are in the structure, the path will always lead direct to the image.

 

I had that issue with includes and since then I always use full paths, it is safer and lest apt to break.

Wow, that's a very detailed and coherent post Kyle. Thank you very much for this great input :)

Link to comment
Share on other sites

Who am I to argue with Kyle!

 

However, I think most people do use relative paths and there is a relative path method that solves Kyle's situation where you move code around to different folders at different levels - use a root-relative link. These ALWAYS go back to the root directory of the website from any file at any level and work down from there to the correct directory/folder and file.

 

http://www.motive.co.nz/glossary/linking.php#root

 

Root-relative links always start with a / like <a href ="/index.php">Motive homepage</a> or <a href ="/images/index.php">Motive homepage</a>

 

Edit: the root-relative links work perfectly from your host's server online, but don't work on your local computer because the root folder is C: which won't create the correct path to the file so you have to check that links work from your online page.

 

So relative and root-relative links do have some disadvantages, which is probably why Kyle plays safe, but most of the rest of us tend to use relative and root-relative links.

Edited by Wickham
Link to comment
Share on other sites

Ha! When did Brits ever not question Ami's eh? wink.gif

 

I was taught relative, and agree most do use it... but I tend to be a Maveric (*snicker* - just taking a shot at Palin and her claims to Maveric-ity in politics... blink.gif)

 

Yea, full is just my preference.

Link to comment
Share on other sites

When it comes to menus, I use full paths when working on sites that has multiple folders.

 

For instance, I have a site that has ecommerce(asp) in one folder, blog(php) in another, gallery(php) in another, etc. Each will use the header/footer (1 asp and 2 php) wrap to give the site the same look throughout. Even though you still have 3 or more headers to work with when it comes to editing it you can easily set up include files within those headers such as a menu. When doing this you will then need to only edit one file to update all your headers' menu regardless if it's php, asp or both. (yes you can run php on a windows server). The menu file will have to be saved as a .txt or .htm (or html) file so that each of the header's includes can render it without problems.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...