SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast Marcelo's Avatar
    Join Date
    Oct 2003
    Location
    Buenos Aires
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Relative or Fixed Paths?

    What way is convenient to make a link? Fixed (http://www.domain.com/webpage.htm) or just relative (Ex: ../webpage.htm)?

    I mean, I know they both work but my idea is to make a discussion from this about what are the advantages and disadvantages of this? Like browser compliants, XHTML compliant, possibilities to use XML, etc.

    Ideas?
    Marcelo

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If there is not a good reason I would always use relative links.

  3. #3
    SitePoint Enthusiast webinista's Avatar
    Join Date
    Oct 2002
    Location
    Stankonia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marcelo
    What way is convenient to make a link? Fixed (http://www.domain.com/webpage.htm) or just relative (Ex: ../webpage.htm)?

    I mean, I know they both work but my idea is to make a discussion from this about what are the advantages and disadvantages of this? Like browser compliants, possibilities to use XML, etc.

    Ideas?
    /webpage.htm is shorter. helps cut down on page weight.


  4. #4
    SitePoint Enthusiast Marcelo's Avatar
    Join Date
    Oct 2003
    Location
    Buenos Aires
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webinista
    /webpage.htm is shorter. helps cut down on page weight.
    What do you mean by shorter?
    Marcelo

  5. #5
    SitePoint Enthusiast Marcelo's Avatar
    Join Date
    Oct 2003
    Location
    Buenos Aires
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drzoid
    If there is not a good reason I would always use relative links.
    That's what I'd like to know. What'd be a good reason and what wouldn't.

    Thanks,
    Marcelo

  6. #6

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marcelo
    What'd be a good reason
    Actually I cant think of one

  7. #7
    SitePoint Addict
    Join Date
    Apr 2003
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll use "../webpage.html" with regards to pages, JS, and CSS. It's just simpler and quicker to do, and it doesn't harm .

    Good reason to do "../webpage.html" is for offline testing using the just mentioned method it's easily to link up your files and test your website in an offline facility, whereas if you have a fixed link, ie http://www.site.com/ then you can't test until you upload any/all documents to your website.

  8. #8
    googlicious graymatter bvarvel's Avatar
    Join Date
    Sep 2002
    Location
    Katy, TX
    Posts
    956
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually use both... in a way. I'll define a variable for the root in a a configuration file.

    PHP Code:
    <?php
    $doc_root 
    "http://localhost/website1";
    ?>
    Then when I need to make links, I do so like:

    PHP Code:
    <a href="<?php echo $doc_root;?>/blah.htm">blah</a>
    That way, I can make it work on my local development server, and then when I upload it, all I have to do is change that variable. This also works wonders should you ever need to change a domain name, use it as a template, blah blah bloggity blah...

  9. #9
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marcelo
    That's what I'd like to know. What'd be a good reason and what wouldn't.

    Thanks,
    actually, i think people here are overlooking the third option, which makes most sense...using just the / to reference anything to the current site's root. webinista touched on it, but didn't explain it enough and was ignored...

    there's lots of good examples of why using THIS is the best solution in certain cases. one of them, for instance: your general stylesheet may be held in www.yoursite.com/common/style.css. on any of your pages you can reference it by using href="/common/style.css". you don't have to worry about where the particular page you're working on is within your site structure, how deep, etc. same for general images like logo etc (<img src="/images/logo.png"...> etc).

    bvarvel...using the above way nullifies the need for ANY php reference to the document root or anything else.

    so, absolute references to the site root (with the / ) make sense for all links/resources that are unlikely to change (your common stylesheets, sections of your site - <a href="/about/">about us</a> -, general images).

    using relative references, on the other hand, makes sense for small, self-contained sections of your site whose overall location my change (e.g. you have lots of pages within the /foo/ directory, and then decide to move it one directory down /foo/bar/...using relative links for all pages within that directory will ensure that links work, and don't need to be changed to reflect the new absolute location).

    so, horses for courses...depends on WHAT you're linking/referncing, really...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  10. #10

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by redux
    actually, i think people here are overlooking the third option, which makes most sense...using just the / to reference anything to the current site's root. webinista touched on it, but didn't explain it enough and was ignored...
    Sure, but in this context I would also see this rather as "relative" url. Absolute in terms of including the hostname.

  11. #11
    Starting to-digg-in ********* jamesxv7's Avatar
    Join Date
    Oct 2003
    Location
    Island of Puerto Rico @ the Caribbean
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RIght now I use absolute links because I get more contro of my links. I had many problems with relative ones and Dreamweaver.
    James: Ecodig - My Blog - My Gallery
    Validate your sites: CSS - HTML/XHTML
    Without faith you are lost.

  12. #12
    SitePoint Enthusiast Marcelo's Avatar
    Join Date
    Oct 2003
    Location
    Buenos Aires
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jamesxv7
    RIght now I use absolute links because I get more contro of my links. I had many problems with relative ones and Dreamweaver.
    What I can see is developers use relative paths for static sites and fixed ones for dynamic so in case they need to change a link from an administrative panel (for example) they can just change it without concerning about where the web page is.
    Any way, is there any other advantage or disadvantage for relative and fixed paths? is one faster than another one? If so, that'll help a lot on what to use.
    Marcelo


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •