Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Using relative links with build_root_url?

Quote Reply
Using relative links with build_root_url?
I have been looking through a bunch of the files in the admin area and was wondering if there wasn't any reason I couldn't just do this
$LINKS{build_root_url} = "";
$LINKS{db_cgi_url} = "/cgi-bin";
to have everything run as relative links instead of repeating the same url over and over again on the page... It seems like just a waste of extra stuff on the pages that aren't needed if all the categories and such are running right under the domain name. But I don't know if there are any other places that this might get me in trouble during the building or anything else because I know the $LINKS{build_root_url} is used in a bunch of places.

Jerry


Quote Reply
Re: Using relative links with build_root_url? In reply to
Hi!

As long as things are anchored with a leading slash you will be fine. i.e.:

build_root_url = '/';

will work, but:

build_root_url = '';

won't.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Using relative links with build_root_url? In reply to
In Reply To:
But I don't know if there are any other places that this might get me in trouble during the building or anything else because I know the $LINKS{build_root_url} is used in a bunch of places.
It will...The problem is that many subs use $LINKS{build_root_url}/ and if you only use "" as the configuration for the $LINKS{build_root_url} then the location of the pages will be screwed up.

What I have done is the following:

1) Use the following configuration for the $LINKS{build_root_url} variable:

Code:

$LINKS{build_root_url} = "/";


2) Then remove / in all subs that use:

Code:

$LINKS{build_root_url}/


in the *.pm files.

It did take me awhile to edit all the .pl files in Links 2.0 and then all the .pm files in LINKS SQL to get this to work.

Regards,

Eliot Lee

Quote Reply
Re: Using relative links with build_root_url? In reply to
Oops...Alex beat me to the bunch. Wink

Regards,

Eliot Lee

Quote Reply
Re: Using relative links with build_root_url? In reply to
Which reminds me, you should really build into a directory, not your document root. Makes it much easier to manage, especially if you want to erase the directory and rebuild everything, don't need to worry about overwriting non links related files. That said, you can set it to:

build_root_url = '/pages';

without any worries.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Using relative links with build_root_url? In reply to
I decided to build in the doc root because I didn't want the extra subdir in the url, some of which can get pretty long, plus it looks like only about 5 pages get built in the main directory - at least it looks like that's all that getting built in my setup.

Thanks for the advice on looking for all the occurences of build_root_url and using just the leading slash in the build_root_url... I figured since the standard practice was that it wasn't added after the domain name in build_root_url meant that it got added everywhere else...

I'll give that a try. I'm just looking to save some space on all my pages where I don't really need the domain name repeated over and over in every link.

Just a thought, this might be a nice option for the next version, to set it so you can either use a / in the build_root_url and have all the other files adjusted to accomodate that or if people preferred they could enter the full url with a slash at the end. Same with cgi one too. Just a thought.

Jerry


Quote Reply
Re: Using relative links with build_root_url? In reply to
Be cautious about where you use relative paths (I used to think they server some purpose for avoiding repeated DNS lookups but have since learned that the domain is cached on the first lookup in the majority of situations, making it a moot point) -- I have encountered things like IE not correctly interpreting relative URL's originating from within the cgi-bin. I would say you're much better off going with a few extra characters in the path name than worry about oddities where the relative paths break down. Local testing and changing domain names are a little less convenient, but who would you rather be inconvenienced, you or your visitors? Wink

Dan

Quote Reply
Re: Using relative links with build_root_url? In reply to
Your points are well taken, Dan...However, I have noticed that using relative paths accomplishes the following:

1) Decreases download time.
2) Saves disk space and real estate in web pages.

Regards,

Eliot Lee

Quote Reply
Re: Using relative links with build_root_url? In reply to
Any ideas why they would result in shorter download times? I've never noticed it being the case.

What do you mean by real estate? File size? I tend to think of screen real estate as viewable area... File size is important, but I don't think the http://www.domain.com/ would make a gigantic difference compared to the rest of the page. There are usually much larger gains to be made elsewhere, like a page I recently worked on, cutting it down from 122k to 65k largely through converting to CSS.

Dan

Quote Reply
Re: Using relative links with build_root_url? In reply to
Yes...I mean file size and the reason is that the smaller the file size, the faster the download, and also I don't totally agree with your DNS lookup statement...using relative links will speed up the download time of pages.

So, I guess we can agree to disagree like always, Dan. Tongue

Regards,

Eliot

Quote Reply
Re: Using relative links with build_root_url? In reply to
Read the following if you are interested:

http://www.aota.net/...2/HTML/000181-1.html

Dan

Quote Reply
Re: Using relative links with build_root_url? In reply to
Interesting Thread...however, IMHO, I believe that relative URLS are much better...and most of the discussion in that Thread describes problems with overlaying web sites and sub-domains, which can be easily alleviated with using relative URLs and also configuring the .htaccess and .htconfig files to use Aliases for shared directory resources.

Regards,

Eliot

Quote Reply
Re: Using relative links with build_root_url? In reply to
Relative URL's have the advantage of allowing easier maintennance of sites, networks, and such.

If pages/links use relative URL's, then no matter where you physically move them, up, down, sideways, the links will always work, based on the first link/URL you called.

The hard thing is to stick with relative URL's and not let "hard" ones slip in.

The only "hard" url's I use are my /cgi-bin and /images and/or /assets type directories. These are directories that are either aliased on the main server, or I set up on each server I use, and they make configuration of headers, includes, and such much easier.

If you have a 'tree' of directories and pages, and you decide you want to group a bunch of things together to clear out the top-level a bit, you can just move them, change the link to that tree, and every other link in the tree would still work. This also allows moving from one domain to another, or going to IP based numbers from DNS, or vice-versa (such as in a test/development system).

As far as the DNS look ups go, if you watch how your browsers function, most do a lookup on a site the first time per session, then cache that DNS information locally for a period of time. They pick up a lot of speed that way.

It's also why if you make a DNS change to your servers, you often have to reboot windows, or at least reload your browser or network stack to get the new information recognized.

Relative URL's are great for moving within related trees, or groups of trees.

They start to fall apart if you use something like ../../../../../ to represent the "root" directory, when '/' is actually the correct way to represent it.

_BUT_ ../Cat_2 would be a proper way to go from one first-level category to another, since it would allow repositioning the categories at a level down.

Nothing is perfect, and no matter if you use hard or relative URLs, you will have to edit or change some links if you rearrange a site.

The advantage of relative URL's is that you almost always have to change far fewer links.

In a dynamically generated site, such as with a <%build_root_url%>, the issue is somewhat less important, since you can move your site just by changing that variable, and re-building. If you use relative URL's, then you can overlay a domain name onto a long path, or alias a long path to a short one, and the links are 'relative' to the starting directory, _not_ the path.

It takes a bit of planning, and thinking through the problem, but it can be done. You couldn't do that with "hard" url's, since a click on a hard URL would effectively toss you out to another server.


http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/