Link paths - Post ID 135750

User 117361 Photo


Ambassador
6,076 posts

Original post by Mark Frost.
Moved from tips and tricks by Janys

I've been using CC html editor for about a year and created a few sites. I've recently started putting pages into folders so that I can keep some content with the page and make site admin easier.

When I create links to other pages, image files etc

CC inserts links from these pages as <li><a href="../../../../index.html">Home</a></li> etc

If you move this page everything stops working.

But if I change the link to <li><a href="http.www.beckerdm.co.uk./index.html">Home</a></li>

I can move the page to any location and everything still works.

Is their any reason, good or bad, why I shouldn't adopting this technique as it seems much easier?

Please help
User 229533 Photo


Registered User
15 posts

I think that Mark just discovered the difference between 'absolute' and 'relative' paths.

It's better to use relative paths (../../) from several reasons:
- if you move the website on another domain, you don't have to rewrite the links hrefs, too
- the browser will send only 1 http request, for the main domain (and pages will load faster)
- it's easier to maintain the website

Beside absolute/relative paths, one can use also the <base> tag. But this is recommended only in the case of huge websites with dynamicaly generated static pages.
www.PinBud.com - do you own a small business? ;)
User 440889 Photo


Registered User
3 posts

Hi Lucian

Thanks for answering my question. If I did use the full path, assuming I don't want to move the site, does that mean every time somebody clicked on a link the browser would send multiple requests?

I only ask this because you mention that the browser only send 1 http request for the domain if you use ../../

As I mentioned, my pages are in lots of sub folders and I intend to grow this site quite quickly over the next few months.

Moving the pages about with full path links just seems so much easier to deal with, or am I missing something and their is an easy way to do this?

Mark
User 184085 Photo


Ambassador
1,707 posts

Quickly looking at your relative path taxonomy it looks like your site is organized up side down, with major files 4 or five levels below the root, so you need to call up numerous levels to get to a file you want.

I'm curious, is there a reason why the menu file would be 5 levels below the index file?

this is how i organize, (folders with a ~ do not get uploaded to a server).

http://i130.photobucket.com/albums/p248/pug2775/coffeecup/coffee_17.jpg
Attachments:
Volunteering to help :)
http://www.tbaygeek.ca
My HTML play area
http://www.tbaygeek.ca/test/
User 562592 Photo


Registered User
2,038 posts

I think the reason is because you should be coding your own links to begin with. The WYSWYG style of link moving is more for those who don't understand that much about coding. the only thing the editor can do is link to where your file is on your computer, so if you move it, it has no way of knowing that. That's why its just better to code yourself, otherwise you cannot move the link locations.
The philosopher has not done philosophy until he has acted upon the mere conviction of his idea; for proof of the theory is in the act, not the idea.

My Web Development Company: http://www.innovatewebdevelopment.com (Created with Coffee Cup Software).

My Personal Website: http://www.EricSEnglish.com

User 229533 Photo


Registered User
15 posts

Mark Eost wrote:

Thanks for answering my question. If I did use the full path, assuming I don't want to move the site, does that mean every time somebody clicked on a link the browser would send multiple requests?


Let's say you have 1 page and in this page you include 3 images, 1 java script file and 1 css file.

If you use absolute paths and include all these elements like: <img src="http://mydomain.com/images/etc." />, <script src="http://mydomain.com/scripts/etc." /> the browser will send 5 different http requests, which is completely useless, because all your files are located under the same domain. The browser will look for "http://mydomain.com" again and again.

Regarding the linked pages, the main problem is that one with website moving. Ok, if you don't want to move your website on another domain, you can live with this, or you can read a little about the tag <base>. If properly used, <base> will make your life much easier. For example, you just define your <base href="http://mydomain.com"> then put all the links, src, hrefs etc. starting from the "base". For example, if you want to include an image in a page located 5 folders in depth, you don't need anymore to say:

<img src="../../../../../images/myimage.jpg" /> or
<img src="http://mydomain.com/images/myimage.jpg" />,

you will just write:

<img src="images/myimage.jpg" />

or for a hyperlink:

<a href="services/mynumber3service.html">My services</a>

However this technique is better used in combination with some php programming.
www.PinBud.com - do you own a small business? ;)
User 2733 Photo


Ambassador
426 posts

If it's a shared server, you could probably avoid all the confusion and use a preceding slash. I.E. from the root directory, and from inside the images folder, grab myimage.jpg.

<img src="/images/myimage.jpg" width="100" height="100" alt="myimage" />


Make certain to include width, height and alt attribs.
Let's not get all hurt.
User 122279 Photo


Senior Advisor
14,624 posts
Online Now

When I set out on creating a new html site, I create a folder, e.g. 'newsite', and inside it I have subfolders like 'css', 'graphics', 'scripts', 'images' and whatever else I need. Then I prepare the images, graphics and all the things I need for the site and stick it into the appropriate folder. That way I have everything organised when I start the actual site building. The actual pages are saved directly in the 'newsite' folder. The linking of the various bits and pieces will then be as David showed in the post above here. I find this the best way, and if I need to move anything, I move the folder 'newsite' and all the contents will be inside it and be moved along
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com



Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.