Absolute vs. Relative Links

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
User avatar
stephen702
Super Advanced
Super Advanced
Posts: 77
Joined: Wed Jul 16, 2003 4:53 am
Location: Davis, CA
Contact:

Absolute vs. Relative Links

Post by stephen702 »

I've been using the Milonic menu as the home page menu only. On other pages, I've linked back to the home page. Now, I'd like to put the Milonic menu on all pages.

My website has several subdirectories. I have a menu_data.js file in the main directory folder, and want to link to it from pages in various subdirectories.

That hasn't worked, however. In order to get menus to display & link properly, I've had to create a second data file in the main directory that's linked from pages in a subdirectory (with ../ in front of all relative URLs), and a third data file that's linked from pages in a sub-subdirectory (with ../../ in front of relative URLs) . That's too complicated.

My question: Will it degrade performance, or slow page loading, if the menu_data.js file uses absolute links for all pages and images--as in the example below?

aI("text=Resource Roster;url=http://aact.org/members/rostersearch.ht ... s=Resource Roster;");

Or is there a better way? Any thoughts are appreciated.
User avatar
Maz
Milonic God
Milonic God
Posts: 1717
Joined: Fri Jun 06, 2003 11:39 pm
Location: San Francisco
Contact:

Post by Maz »

I find it a bit confusing, but I had a similar problem at first but it works fine now.

I have a path of /1/2/menu_files.js

One path is /forum/ but it still has the same link /1/2/menu-files.js

It knows to go back and start from the root. There is no need for ...

Absolute links will work fine, but I find I don't need them anymore.

I'm not sure why you have a problem, perhaps putting the menu files in its own folder would help putting it down a level to /menu/menu_data.js
and /menu/images/menu.gif will help.

Regards,
maz
User avatar
bobwill
Mega Advanced
Mega Advanced
Posts: 229
Joined: Tue Oct 01, 2002 3:03 pm
Location: Kansas
Contact:

Post by bobwill »

Using your example, I am assume that your root directoy is http://aact.org/

Therefore to access other files that are either in the root directory or a sub-directory off of root your code would be.
aI("text=Resource Roster;url=/members/rostersearch.html;image= /images/dot_gold.gif;status=Resource Roster;");

If you had a file in the root directory then it would be, url=/myfile.html
User avatar
John
 Team
 Team
Posts: 5967
Joined: Sun May 19, 2002 8:23 pm
Location: Phoenix, AZ
Contact:

Post by John »

An absolute link will work, and should not cause any performance problems, but it is quite restrictive. For instance, what if you need to move sites?

What Maz and Bob have outlined is called server-relative addressing, and is the way to go. All your URLs, including the menu JS calls, are written relative to the root server address. This way, regardless of how deep your site might go, the code remains the same.
John
User avatar
stephen702
Super Advanced
Super Advanced
Posts: 77
Joined: Wed Jul 16, 2003 4:53 am
Location: Davis, CA
Contact:

Post by stephen702 »

Thanks for all your suggestions. The relative linking via a path works well.
Post Reply