Brainstorms and Raves

Notes on Web Design, Development, Standards, Typography, Music, and More

Sun

7

SEP

2003

Relative vs. Absolute URLs

As much as I love using Movable Type, a few things have bothered me about MT, too, such as MT generating absolute URLs for internal links when relative URLs should be used. Stepan Riha’s MTRelativeURL plugin is an incredibly easy way to generate relative URLs with MT, thankfully, wherever the plugin tags are used.

For example, a permalink generated by Movable Type includes the site URL, such as this:

<a href="http://brainstormsandraves.com/
entry_permalink/" rel="bookmark" title="Entry title">
Permalink</a>

Root relative links should instead be used for nearly all of a site’s internal sites, such as this:

<a href="/entry_permalink/" rel="bookmark" title="Entry title">Permalink</a>

An exception where absolute URLs are required is within RSS feeds for which absolute URLs are currently still needed. So don’t use the MTRelativeURL plugin tags within your MT RSS templates, at least not unless the absolute URL requirement changes at some point.

There are at least a couple of ways to use the MTRelativeURL plugin for an entry’s permalink, but one way is to surround the <$MTEntryLink$> tag with the MTRelativeURL tags:

Before:
<a href="<$MTEntryLink$>" rel="bookmark" title="<$MTEntryTitle remove_html="1"$>">Permalink</a>

After:
<a href="<MTRelativeURL><$MTEntryLink$>
</MTRelativeURL>" rel="bookmark" title="<$MTEntryTitle remove_html="1"$>">
Permalink</a>

Here’s the same example without the text wrapping: MTRelativeURL Example

See Stepan Riha’s MTRelativeURL plugin page for more information and details in its use.

Agh! Help! They’re Everywhere!

There are potentially quite a few internal links throughout your site in which MT is generating absolute URLs, not just the permalinks. This is also a very unnecessary waste of bandwidth, as I write about below in Save Bandwidth.

Over the weekend I added MTRelativeURL tags for MT-generated internal links throughout my templates. It’s an easy task that doesn’t take long while having tremendous benefit. Here’s a partial list from my own templates to give you an idea of where to look in your templates:

Main page, individual entry pages:
Permalinks
Related Categories links
Comments / Trackbacks links
Previous, Next links
Main Archive page:
Archives by Category links
Archives by Month links
Category Archive pages:
Entry links

[Cover: Speed Up Your Site, by Andy King] Save Bandwidth

One of the benefits of using relative URLs is shaving off some webpage file size, saving some or a lot of bandwidth, depending on the page.

  • I shaved off 2KB on my main page just by using the MTRelativeURL plugin for my internal links.
  • Where the file size is really noticeable, though, is a high content page like my Archives by Title page that lists over 2-1/2 years' worth of entries on a single page—I shaved off 23KB just by using the MTRelativeURL plugin for all the internal links, saving bandwidth and page load time especially for dial-up users.
  • I also saved 5KB with each of my Archives by Year pages that provide calendar views with links to each day’s entry, such as the 2002 Calendar Archive.

You can improve file size, save bandwidth, and have more efficient pages in other ways, too, such as getting rid of white-space within markup and content, optimizing images, using external style sheets to manage an entire site, and more. I highly recommend Andy King’s site optimization book, Speed Up Your Site.

More on Relative and Absolute URLs

A couple of helpful resources to understand relative and absolute URLs and why they matter:

04:13 pm, pdt 7 September, 2003 Comments, Trackbacks (8) ·

Categories: Books, Colophon, Development, Movable Type, SEO

Comments

Comments, Trackbacks: 8 so far. Add yours!

  1. It may be that way by default because you can include HTML as CDATA in your RSS feeds. HTML in RSS is not the cleanest solution, but it usually reads better in most RSS readers, mainly because it retains it’s paragraph formatting.

    Anyway, if you had a link as a relative URL from your RSS feed, there is no clear definition of what that link should be relative to. Might be your blog directory, might be your root, who knows? I think the RSS validator notes relative URLs as an error. Anyway, it’s something to consider. Cheers.

    11:49 pm, pdt 7 September, 2003Comment by James Craig

    comment #1 permalink ·

  2. I’ve run into the same issue as James.

    I’d imagine they’re probably addressing this in Atom with some baseurl=whatever attribute for all feeds.

    One nasty implication of absolute URLs is that everywhere your site is syndicated, your inline images appear. And that means bandwidth costs.

    08:48 am, pdt 8 September, 2003Comment by Joe Grossberg

    comment #2 permalink ·

  3. Listamatic provides examples of creating lists and navigation bars using CSS. While on the topic of CSS, Douglas Bowman wrote, “Making the Absolute, Relative” based on a question he received...

    08 Sep, 2003Trackback from meryl's notes

    trackback #3 permalink ·

  4. One day, I will be able to blog with significant content like "Relative vs. Absolute URLs" at Brainstorms and Raves. As a user of Movable Type, I'll admit, I haven't even thought about file size issues with using absolute URLs...

  5. Well I'm back and almost raring to go after a rather severe stomach upset that hit me on returning from my holiday that kept me away from the computer for a while. While working on the redesign of the blog...

    09 Sep, 2003Trackback from twenty4.org

    trackback #5 permalink ·

  6. Thanks for your comments. There are more than a few approaches to RSS feeds and whether or not it’s OK to even use HTML in them or not. I lean toward the approach NOT to include HTML in them. That also removes a problem with images and bandwidth problems, too, of course.

    However, my post was really about the MTRelativeURL plugin and not about whether or not to use HTML in RSS feeds... which is a hotly debated topic right along with whether to provide summaries or complete posts.

    But yes, the folks on the Atom team have been discussing relative vs. absolute URLs. I don’t know what they’ll end up with, though, which is why I made the comment that I did. I mainly just wanted to alert people not to use that plugin within their RSS feed templates.

    Thanks for your comments and for reading my website post!

    11:23 pm, pdt 9 September, 2003Comment by Shirley Kaiser

    comment #6 permalink ·

  7. One day, I will be able to blog with significant content like "Relative vs. Absolute URLs" at Brainstorms and Raves. As a user of Movable Type, I'll admit, I haven't even thought about file size issues with using absolute URLs...

  8. Listamatic provides examples of creating lists and navigation bars using CSS. While on the topic of CSS, Douglas Bowman wrote, “Making the Absolute, Relative” based on a question he received...

    21 Mar, 2005Trackback from meryl's notes

    trackback #8 permalink ·

This discussion has been closed. Thanks to all who participated.

top


Visit iStockPhoto - Royalty-free stock images. Click Upload Earn, Click Download Create 

I Wrote a Book

Deliver First Class Web Sites: 101 Essential Checklists  Via amazon.com: Deliver First Class Web Sites: 101 Essential Checklists, by Shirley Kaiser. SitePoint Books (July 2006). 

Available now via: SitePoint Books, Amazon.com, Amazon.ca (Canada), Amazon.co.uk (UK), Amazon.fr (France), Amazon.de (Germany), Amazon.co.jp (Japan), Tower Books U.S. and elsewhere! You'll also help support this site and its owner if you purchase via any of these links.

Learn more at SKDesigns - Deliver First Class Web Sites and via SitePoint Books.

Recommended Books

Cover - Web Design in a Nutshell : A Desktop Quick Reference, 3rd Ed. By Jennifer Niederst Robbins. Pub: OReilly Media (February 21, 2006).

Cover - Deliver First Class Web Sites: 101 Essential Checklists, by Shirley Kaiser. SitePoint Books (July 2006).

Hand-picked best book recommendations for Web site design, CSS, graphics, Photoshop, color, accessibility, more

In association with
 In Association with Amazon.com 
http://brainstormsandraves.com/archives/2003/09/07/relative_vs_absolute_urls/
Page last modified 14 July, 2007 - 10:20pm PDT Page load time: 0.010664 seconds.