10/16/2005; 1:30:57 AM
I had accesskeys for the tabs at the top of this site, but Mark Wubben reminded me that this was very annoying, mainly because alt-d was one of them (the shortcut to focus the address bar). This makes me think that using accesskeys in webpages is not a very good idea, because you never know what the favorite shortcut keys of your visitor are.
If you're wondering what a base URI is for, you'll always end up being directed to RFC 3986, but you won't find much. Section 5.1 just says: “The term "relative" implies that a "base URI" exists against which the relative reference is applied.”. But that there's more to it becomes apparent when same-document references come into play. One example is Tim Bray's atom feed. Here is part of it:
<feed xmlns='http://www.w3.org/2005/Atom' xml:base='http://www.tbray.org/ongoing/' xml:lang='en-us'> <title>ongoing</title> <link href='' />
As the base URI is already "http://www.tbray.org/ongoing/", the link to Tim's homepage can be the empty URI. However, according to RFC 3986, this is a same-document reference. It still references the correct URI, so usually you won't notice. But there are cases where this goes wrong, f.e. the XPath 2.0 expression fn:doc(/feed/link/@href)
will get you the current atom document, not the document at http://www.tbray.org/ongoing/. What's worse, you can't fix this by changing the link to <link href='http://www.tbray.org/ongoing/' />
, as the link is still the same as the base URI, so it still is a same-document reference.
So it seems you can't just use any base URI, but only the original URI of the content. Final proof comes from a discussion on the W3C URI mailing list. Here Roy T. Fielding, the author of RFC 3986, says: “[...] a person is deliberately abusing the base URI by assigning it an unrelated URI for the purpose of creating an artificial shorthand notation for external references.” Good to know!
I find it really odd that Roy calls something an abuse, which by most web developers is considered to be the only purpose of a base URI! And that he has added nothing to the new RFC 3986 to make this clear in any way. So we will have to do this ourselves. Spread the word: Stop the abuse of base URIs! I also hope Tim Bray will fix his atom file, as his feed is used as an example by many, so this abuse might spread to a lot of atom files.
[Update] Here's another example of base URI abuse in Atom.
To recap:
- Only use the actual URI of the document as its base URI, or the original URI if the document is moved. (This might actually be a good practice, with the same purpose as the self link in Atom.)
- If you use xml:base, add an xml:base attribute on content that is included from another document. (This happens automatically if you use XInclude.)
- Don't use the base URI for anything else.
Finally I'd like to share a trick to set the base URI for escaped HTML in RSS and Atom: add a BASE element to the beginning of the HTML content. This will work for most aggregators that run in a browser, like Bloglines, or use a browser component to display HTML, like most e-mail client based aggregators. Having multiple BASE elements in one HTML document, while not valid, works fine in most browsers. Aggregators can use this trick themselves as well.