我正在设计一个永久链接系统,我刚刚注意到 Twitter 和 Hipmunk 都在其永久链接前面加上了 #!
前缀。我想知道这是为什么,以及感叹号的存在是否有原因。 #/
是否也能正常工作,因为他们无疑使用了一个框架,可以让他们使用正则表达式 URL 解析器将查询重定向到某些模板?
http://www.hipmunk.com/#!BOS.SEA,Dec15.Jan02
http://twitter.com/#!/dozba
我唯一的猜测是因为浏览器使用 #
链接到锚元素。这就是为什么要加上感叹号吗?
I'm designing a permalink system and I just noticed that Twitter and Hipmunk both prefix their permalinks with #!
. I was wondering why this is, and if the exclamation point in particular is there for a reason. Wouldn't #/
work just as well, since they're no doubt using a framework that lets them redirect queries to certain templates with a regex URL parser?
http://www.hipmunk.com/#!BOS.SEA,Dec15.Jan02
http://twitter.com/#!/dozba
My only guess is it's because browsers use #
to link to an anchor element. Is this why the exclamation point is appended?
发布评论
评论(2)
这样做是为了使“AJAX”页面可以[由谷歌]抓取以进行索引——它不会影响片段标识符!
请参阅使 AJAX 应用程序可抓取:入门
我确信其他搜索引擎也在遵循这个引导/协议。
快乐编码。
另外,至少在 HTML5 中,拥有 ID 为“!foo”的元素实际上是完全有效的,因此
帖子中的推理无效。请参阅文章“id 属性变得更加优雅”:
This is done to make an "AJAX" page crawlable [by google] for indexing -- It does not affect the other well-defined semantics of the fragment identifier at all!
See Making AJAX Applications Crawlable: Getting Started
I am sure other search-engines are also following this lead/protocol.
Happy coding.
Also, It is actually perfectly valid, at least per HTML5, to have an element with an ID of "!foo" so the
reasoning in the post is invalid. See the article "The id attribute just got more classy":
我的猜测是,这两个页面在其 JavaScript 中都使用了这一点来区分
#
(指向锚点的链接)和自定义#!
(使用 Ajax 加载一些附加内容)。在这种情况下,
#
符号之后几乎所有其他内容都会起作用。My guess is that both pages use this in their JavaScript to differ between
#
(a link to an anchor) and their custom#!
which loads some additional content using Ajax.In that case pretty much everything else would work after the
#
sign.