酷URI永不变:Web架构师Tim Berners-Lee谈URI设计原则
酷URI永不变(1998)
Cool URIs don't change
酷 URI 不会改变
What makes a cool URI?
什么造就了酷 URI?
A cool URI is one which does not change.
酷 URI 是指不会改变的 URI。
What sorts of URI change?
哪些 URI 会改变?
URIs don't change: people change them.
URI 不会改变:是人们在改变它们。
There are no reasons at all in theory for people to change URIs (or stop maintaining documents), but millions of reasons in practice.
理论上,人们没有任何理由改变 URI(或停止维护文档),但实践中有无数理由。
In theory, the domain name space owner owns the domain name space and therefore all URIs in it. Except insolvency, nothing prevents the domain name owner from keeping the name. And in theory the URI space under your domain name is totally under your control, so you can make it as stable as you like. Pretty much the only good reason for a document to disappear from the Web is that the company which owned the domain name went out of business or can no longer afford to keep the server running. Then why are there so many dangling links in the world? Part of it is just lack of forethought. Here are some reasons you hear out there:
理论上,域名空间所有者拥有域名空间及其中的所有 URI。除非破产,没有什么能阻止域名所有者保留该名称。而且理论上,你域名下的 URI 空间完全由你控制,所以你可以让它尽可能稳定。文档从网络上消失的几乎唯一正当理由是,拥有该域名的公司倒闭或无力再维持服务器运行。那么,为什么世界上有这么多失效链接呢?部分原因只是缺乏远见。以下是一些你常听到的理由:
We just reorganized our website to make it better.
我们刚刚重组了网站,使其更好。
Do you really feel that the old URIs cannot be kept running? If so, you chose them very badly. Think of your new ones so that you will be able to keep then running after the next redesign.
你真的觉得旧 URI 无法继续运行吗?如果是这样,那你当初选择得很糟糕。想想你的新 URI,以便在下一次重新设计后仍能继续运行它们。
We have so much material that we can't keep track of what is out of date and what is confidential and what is valid and so we thought we'd better just turn the whole lot off.
我们有太多材料,无法跟踪哪些已过时、哪些是机密的、哪些是有效的,所以我们认为最好把整个都关掉。
That I can sympathize with - the W3C went through a period like that, when we had to carefully sift archival material for confidentiality before making the archives public. The solution is forethought - make sure you capture with every document its acceptable distribution, its creation date and ideally its expiry date. Keep this metadata.
这我能理解——W3C 也经历过类似时期,当时我们在公开档案前必须仔细筛选机密内容。解决办法是提前规划——确保每份文档都记录其可分发范围、创建日期,理想情况下还有过期日期。保留这些元数据。
Well, we found we had to move the files...
嗯,我们发现必须移动文件……
This is one of the lamest excuses. A lot of people don't know that servers such as Apache give you a lot of control over a flexible relationship between the URI of an object and where a file which represents it actually is in a file system. Think of the URI space as an abstract space, perfectly organized. Then, make a mapping onto whatever reality you actually use to implement it. Then, tell your server. You can even write bits of your server to make it just right.
这是最蹩脚的借口之一。很多人不知道像 Apache 这样的服务器能让你在对象的 URI 与表示它的文件在文件系统中的实际位置之间建立灵活的关系。把 URI 空间想象成一个抽象空间,完美组织。然后,将其映射到你实际使用的任何实现上。然后,告诉你的服务器。你甚至可以编写服务器代码来使其恰到好处。
John doesn't maintain that file any more, Jane does.
约翰不再维护那个文件了,现在是简在维护。
Whatever was that URI doing with John's name in it? It was in his directory? I see.
那个 URI 里为什么有约翰的名字?它在约翰的目录下?我明白了。
We used to use a cgi script for this and now we use a binary program.
我们以前用 CGI 脚本,现在用二进制程序。
There is a crazy notion that pages produced by scripts have to be located in a "cgibin" or "cgi" area. This is exposing the mechanism of how you run your server. You change the mechanism (even keeping the content the same ) and whoops - all your URIs change.
有一种疯狂的想法,认为由脚本生成的页面必须放在“cgibin”或“cgi”目录下。这暴露了你运行服务器的机制。你改变了机制(即使内容保持不变),哎呀——你所有的URI都变了。
For example, take the National Science Foundation:
例如,以国家科学基金会为例:
NSF Online Documents
NSF在线文档
http://www.nsf.gov/cgi-bin/pubsys/browser/odbrowse.pl
http://www.nsf.gov/cgi-bin/pubsys/browser/odbrowse.pl
the main page for starting to look for documents, is clearly not going to be something to trust to being there in a few years. "cgi-bin" and "oldbrowse" and ".pl" all point to bits of how-we-do-it-now. By contrast, if you use the page to find a document, you get first an equally bad
开始查找文档的主页,显然不能指望它在几年后仍然存在。“cgi-bin”、“oldbrowse”和“.pl”都指向了我们当前实现方式的细节。相比之下,如果你使用该页面查找文档,你首先会得到一个同样糟糕的
Report of Working Group on Cryptology and Coding Theory
密码学与编码理论工作组报告
http://www.nsf.gov/cgi-bin/getpub?nsf9814
http://www.nsf.gov/cgi-bin/getpub?nsf9814
for the document's index page, but the html document itself by contrast is very much better:
作为文档的索引页,但相比之下,HTML文档本身要好得多:
http://www.nsf.gov/pubs/1998/nsf9814/nsf9814.htm
http://www.nsf.gov/pubs/1998/nsf9814/nsf9814.htm
Looking at this one, the "pubs/1998" header is going to give any future archive service a good clue that the old 1998 document classification scheme is in progress. Though in 2098 the document numbers might look different, I can imagine this URI still being valid, and the NSF or whatever carries on the archive not being at all embarrassed about it.
看看这个,“pubs/1998”这个头部会给任何未来的存档服务一个很好的线索,表明旧的1998年文档分类方案正在进行中。尽管在2098年文档编号可能会有所不同,但我可以想象这个URI仍然有效,而NSF或任何继续存档的机构对此不会感到尴尬。
I didn't think URLs have to be persistent - that was URNs.
我以为URL不必是持久的——那是URN的事。
This is the probably one of the worst side-effects of the URN discussions. Some seem to think that because there is research about namespaces which will be more persistent, that they can be as lax about dangling links as they like as "URNs will fix all that". If you are one of these folks, then allow me to disillusion you.
这可能是URN讨论带来的最糟糕的副作用之一。有些人似乎认为,因为存在关于更持久命名空间的研究,他们就可以对失效链接漫不经心,认为“URN会解决所有问题”。如果你是这些人中的一员,请允许我让你醒悟。
Most URN schemes I have seen look something like an authority ID followed by either a date and a string you choose, or just a string you choose. This looks very like an HTTP URI. In other words, if you think your organization will be capable of creating URNs which will last, then prove it by doing it now and using them for your HTTP URIs. There is nothing about HTTP which makes your URIs unstable. It is your organization. Make a database which maps document URN to current filename, and let the web server use that to actually retrieve files.
我见过的大多数URN方案看起来都像是一个权威ID,后面跟着一个日期和你选择的字符串,或者只是一个你选择的字符串。这看起来非常像HTTP URI。换句话说,如果你认为你的组织有能力创建持久的URN,那么现在就证明它,并用它们作为你的HTTP URI。HTTP本身并不会使你的URI不稳定。问题在于你的组织。建立一个数据库,将文档URN映射到当前文件名,并让Web服务器使用它来实际检索文件。
If you have gotten to this point, then unless you have the time and money and contacts to get some software design done, then you might claim the next excuse:
如果你已经读到这里,那么除非你有时间、金钱和人脉来完成一些软件设计,否则你可能会提出下一个借口:
We would like to, but we just don't have the right tools.
我们愿意这样做,但我们就是没有合适的工具。
Now here is one I can sympathize with. I agree entirely. What you need to do is to have the web server look up a persistent URI in an instant and return the file, wherever your current crazy file system has it stored away at the moment. You would like to be able to store the URI in the file as a check, and constantly keep the database in tune with actuality. You'd like to store the relationships between different versions and translations of the same document, and you'd like to keep an independent record of the checksum to provide a guard against file corruption by accidental error. And web servers just don't come out of the box with these features. When you want to create a new document, your editor asks you for a URI instead of telling you.
现在这个我能理解。我完全同意。你需要做的是让网络服务器瞬间查找一个持久URI并返回文件,无论你当前疯狂的文件系统把它存储在何处。你希望能够将URI存储在文件中作为检查,并不断使数据库与实际保持一致。你希望存储同一文档的不同版本和翻译之间的关系,并且希望保留独立的校验和记录,以防止意外错误导致文件损坏。而网络服务器开箱即用时并不具备这些功能。当你想要创建新文档时,你的编辑器会要求你提供URI,而不是告诉你。
You need to be able to change things like ownership, access, archive level security level, and so on, of a document in the URI space without changing the URI.
你需要能够在URI空间中更改文档的所有权、访问权限、归档级别、安全级别等,而不改变URI。
Too bad. But we'll get there. At W3C we use Jigedit functionality (Jigsaw server used for editing) which does track versions, and we are experimenting with document creation scripts. If you make tools, servers and clients, take note!
太糟糕了。但我们会做到的。在W3C,我们使用Jigedit功能(用于编辑的Jigsaw服务器),它确实跟踪版本,并且我们正在尝试文档创建脚本。如果你制作工具、服务器和客户端,请注意!
This is an outstanding reason, which applies for example to many W3C pages including this one: so do what I say, not what I do.
这是一个突出的原因,适用于许多W3C页面,包括这个页面:所以照我说的做,不要照我做的做。
Why should I care?
我为什么要在意?
When you change a URI on your server, you can never completely tell who will have links to the old URI. They might have made links from regular web pages. They might have bookmarked your page. They might have scrawled the URI in the margin of a letter to a friend.
当你更改服务器上的URI时,你永远无法完全知道谁会有指向旧URI的链接。他们可能从普通网页上做了链接。他们可能收藏了你的页面。他们可能把URI潦草地写在给朋友的信的页边空白处。
When someone follows a link and it breaks, they generally lose confidence in the owner of the server. They also are frustrated - emotionally and practically from accomplishing their goal.
当有人点击链接而链接失效时,他们通常会对服务器所有者失去信心。他们也会感到沮丧——无论是情感上还是实际达成目标上。
Enough people complain all the time about dangling links that I hope the damage is obvious. I hope it also obvious that the reputation damage is to the maintainer of the server whose document vanished.
一直有足够多的人抱怨死链,我希望损害是显而易见的。我也希望显而易见的是,声誉损害是对服务器维护者的,因为他们的文档消失了。
So what should I do? Designing URIs
那么我该怎么办?设计URI
It is the the duty of a Webmaster to allocate URIs which you will be able to stand by in 2 years, in 20 years, in 200 years. This needs thought, and organization, and commitment.
网站管理员有责任分配URI,这些URI在2年、20年、200年后你都能坚持使用。这需要思考、组织和承诺。
URIs change when there is some information in them which changes. It is critical how you design them. (What, design a URI? I have to design URIs? Yes, you have to think about it.). Designing mostly means leaving information out.
当URI中包含某些变化的信息时,URI就会改变。你如何设计它们至关重要。(什么,设计URI?我必须设计URI?是的,你必须考虑它。)。设计主要意味着省略信息。
The creation date of the document - the date the URI is issued - is one thing which will not change. It is very useful for separating requests which use a new system from those which use an old system. That is one thing with which it is good to start a URI. If a document is in any way dated, even though it will be of interest for generations, then the date is a good starter.
文档的创建日期——即URI发布的日期——是不会改变的一件事。它对于区分使用新系统的请求和使用旧系统的请求非常有用。这是URI开头的一个好选择。如果文档在任何方面注明了日期,即使它将在几代人中引起兴趣,那么日期也是一个好的开头。
The only exception is a page which is deliberately a "latest" page for, for example, the whole organization or a large part of it.
唯一的例外是故意作为“最新”页面的页面,例如,针对整个组织或其大部分。
http://www.pathfinder.com/money/moneydaily/latest/
http://www.pathfinder.com/money/moneydaily/latest/
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力