23

Apparently using the URL is no good - why is this the case, and how do you generate a good one?

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Rich Bradshaw
  • 71,795
  • 44
  • 182
  • 241

2 Answers2

33

Mark Pilgrim's article How to make a good ID in Atom is good. Here's part of it:

Why you shouldn’t use your permalink as an Atom ID

It’s valid to use your permalink URL as your <id>, but I discourage it because it can create confusion about which element should be treated as the permalink. Developers who don’t read specs will look at your Atom feed, and they see two identical pieces of information, and they pick one and use it as the permalink, and some of them will pick incorrectly. Then they go to another feed where the two elements are not identical, and they get confused.

In Atom, <link rel="alternate"> is always the permalink of the entry. <id> is always a unique identifier for the entry. Both are required, but they serve different purposes. An entry ID should never change, even if the permalink changes.

“Permalink changes”? Yes, permalinks are not as permanent as you might think. Here’s an example that happened to me. My permalink URLs were automatically generated from the title of my entry, but then I updated an entry and changed the title. Guess what, the “permanent” link just changed! If you’re clever, you can use an HTTP redirect to redirect visitors from the old permalink to the new one (and I did). But you can’t redirect an ID.

The ID of an Atom entry must never change! Ideally, you should generate the ID of an entry once, and store it somewhere. If you’re auto-generating it time after time from data that changes over time, then the entry’s ID will change, which defeats the purpose.

cjm
  • 61,471
  • 9
  • 126
  • 175
  • 1
    thanks for the internet archive link - i had linked to his original post a couple of years ago and just found it gone. then i remembered [Hanselman's Article](http://www.hanselman.com/blog/410GoneThoughtsOnMarkDiveintomarkPilgrimsAndWhysInfosuicides.aspx) – Jeff Martin Sep 21 '12 at 14:52
  • One should note this: "The ID must be globally unique, across all Atom feeds, everywhere, for all time.". I asked myself this very question so some others might as well. – jeromej Sep 22 '13 at 01:11
  • 3
    This answer is a bit focused on what to avoid. So what should we do? Use a [tag URI](http://www.taguri.org/), as specified in [RFC 4151](http://www.faqs.org/rfcs/rfc4151.html). – Magnus Hoff Mar 21 '14 at 11:15
  • It is idiotic to write a certain code because "developers will get confused". If they don't know what the id tag is, they shouldn't develop. –  Apr 12 '15 at 12:22
  • 1
    The author(s) are talking about Wordpress style permalinks, not real permanent links. Wordpress permalinks are simply "clean urls" which are dynamic. Real permalinks are static, based on entity ID, & don't change unless the entity is deleted. So yes, it is indeed acceptable to use **real** permalinks for ``, and you should def always use them for `rel="alternate"` too. – dhaupin Jul 16 '15 at 18:55
2

Use a GUID for the ID.

depends what language you use, but you could use

System.Guid for .NET.

SpoiledTechie.com
  • 10,515
  • 23
  • 77
  • 100
  • 1
    or java.util.UUID for, um, java – skaffman Sep 29 '08 at 21:26
  • the more human readable taguri described in the article linked by @cjm can often be more useful. – Jeff Martin Sep 21 '12 at 14:53
  • One caution for using a GUID would be that the ID should ideally be unique across ALL feeds anywhere. Though the chance of having a collision would be small it would exist, so prefix it with the site domain or similar to make sure they're unique. – DjB Nov 24 '17 at 04:25