www.webdeveloper.com
Results 1 to 9 of 9

Thread: Absolute or relative paths?

  1. #1
    Join Date
    Oct 2010
    Posts
    20

    Absolute or relative paths?

    For many links between pages on the same folder level, I use relative paths (like home/products/contact, etc.).

    Once you move to a deeper level, of course, those links need to be adjusted. One way of dealing with this would be to change all the links to absolute paths (http://www...). Then I could just reuse the same code on all folder levels.

    I'm just curious to know if there is any speed penalty of using one way over the other.

    Thanks,
    stefangs

  2. #2
    Join Date
    Nov 2006
    Location
    Springfield, MO
    Posts
    1,541
    If you use http://www. then if your domain name changes, you're hosed. I'd just site-root relative:

    /home/products/contact
    Ryan Butler

    Ryan Butler.org

  3. #3
    Join Date
    Mar 2011
    Posts
    1,109
    The speed difference between relative and absolute paths is negligible - especially when considered among all of the other factors that go into how a web page is loaded.

    My main concern with relative links/paths is potential search engine issues. You can run into what are called "canonicalization" issues when search engines start to crawl your site with and without the "www." subdomain prefix or the "https://" protocol and they start to "discover" duplicates of all of your pages. Dynamically-generated sites can also lead search engines into unending mazes of nested psuedo-directories that can be a problem. Then there are the rogue sites out there that copy your content. If you use absolute addressing for navigation, you stand a better chance of the links on those copies sending users (and search engines) back to your site instead of deeper into the thief's site.

    These problems are generally easy to repair if you know what you're doing, but it can take many weeks to recover. And when it's your site (or income!) that is affected, that can feel like a very long time. So, although I don't want to exaggerate the potential problems involved, I tend to be religious about using absolute addressing for navigation, especially to the home page, for all of the sites I manage.
    Rick Trethewey
    Rainbo Design

  4. #4
    Join Date
    Oct 2010
    Posts
    20
    Thank you Ryan and Rick for your thoughts!

    @Rick - a whole new way of looking at things. My sites aren't dynamically generated, just plain HTML, so some of the stuff you mentioned may not apply, but it sure is interesting (and scary to boot!).

    Thanks,
    stefangs

  5. #5
    Join Date
    Oct 2010
    Posts
    20
    Quote Originally Posted by ryanbutler View Post
    If you use http://www. then if your domain name changes, you're hosed. I'd just site-root relative:

    /home/products/contact
    Hmm, beginning with a / does not seems to get me to the root level.

    By way of example, the index page in my root level uses an image from a folder with images, like this:
    <img src="images/logo.png">

    There is also a directory with products where each product has its own folder, so the index page of a product is 2 levels down from the root level:

    root > products > product_a > index.html

    To use the same image, so far I used:
    <img src="../../images/logo.png">

    Using
    <img src="/images/logo.png">
    as I understand your suggestion, doesn't work.

    Can I somehow use a single relative definition of the path? I know that absolute will work, it's just cumbersome to edit offline.

    Thanks,
    stefangs

  6. #6
    Join Date
    Mar 2011
    Posts
    1,109
    The root-relative path won't be the same on your computer as it would be on your website (which would resolve to something like "C:/..."). So, as long as you intend to develop locally, I wouldn't recommend using it on external resources like images or stylesheets. Stick to using simple relative paths.
    Rick Trethewey
    Rainbo Design

  7. #7
    Join Date
    Oct 2010
    Posts
    20
    Oh you are saying that the root relative path method above won't work in offline mode but will work once the page is hosted. Excellent... I get it.

    Thanks,
    stefangs

  8. #8
    Join Date
    Aug 2013
    Posts
    13
    There is no speed penality but it is fine to use relative path. Absolute path usually change when site is shifted or you add some plugin like it often happens with me in wordpress.

  9. #9
    Join Date
    Oct 2010
    Posts
    20
    Yes, I 'm quite happy with Rick's suggestion. I'm fine with busted layouts while offline and checking online every now and again while developing.

    stefangs

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles