去哈希邦还是不去哈希邦?
我正在开发一个新网站,我想尽可能地利用 AJAX。基本上,我希望用户几乎永远不会离开主页,并在弹出窗口、滑块、部分等中显示所有内容。
现在我们现有的网站已经排名很高,所以我也想让谷歌满意。我一直在阅读 Google 的使 AJAX 应用程序可抓取,并且了解我必须通过 _escaped_fragment_ 为抓取工具提供相同的内容。
问题
我想使用 Umbraco 开发这个网站,它已经提供了 SEO 友好的 URL。 ie
但问题是我没有一个简单的方法实现_escaped_fragment_而不破解Umbraco核心(至少这是我的知识),并且使用我在下面发布的解决方案(答案)也将使没有Javascript的用户感到满意。双赢?你告诉我吧! =)
更新
昨天有另一位用户的回答(现已删除),他建议 Google 不再使用 _escaped_fragment_ 方法,并建议忽略此方法。这是真的吗? Google 真的会运行 AJAX 来查看内容吗?
谢谢
马尔科
I'm developing a new website and I'd like to make use of AJAX as much as possible. Basically, I want users to almost never navigate away from the homepage and have everything displaying in popup windows, sliders, sections etc.
Now our existing website already ranks pretty high so I also want to keep Google happy. I've been reading the Making AJAX Applications Crawlable by Google and understand that I have to provide the same content for the crawler via _escaped_fragment_.
The problem
I want to develop this website using Umbraco which already provides SEO-friendly URLs. i.e.
But the issue is that I don't have an easy way of implemeting _escaped_fragment_ without hacking the Umbraco core (at least that's my knowledge), and using the solution(answer) I have posted below will also keep users without Javascript happy. Win-Win situation? You tell me! =)
Update
There was an answer from another user yesterday (now deleted) who suggested that Google no longer uses the _escaped_fragment_ method and suggested this be left out. Is this true? Will Google actually run the AJAX to see the content?
Thanks
Marko
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我采纳了 @Daniel Pryden 评论中的建议,并将其作为答案发布。
我思考过这个问题并想 - 为什么不以老式方式创建网站、实际页面和所有内容,然后执行以下步骤。
window.location.pathname
前面添加井号 (#),从而触发 hashchange 事件。 (请参阅步骤 3)window.location.pathname
。例如,Google 抓取 http://www.domain.com/about-us.aspx 但是当用户访问该页面时,他们会被重定向到 http://www.domain .com/#/about-us.aspx这样,没有 Javascript 的用户将拥有一个成熟的(半好看的)网站,Google 将毫无问题地抓取所有页面,但使用 Javascript 的用户将始终停留在主页上 - 以及拥有一个很酷的概念将完成 Web 应用程序而不是网站。
I'm taking the advice from @Daniel Pryden's comment and posting this as an answer instead.
I had a think about this problem and thought - why not create the website in an old fashioned manner, actual pages and everything but then perform the following steps.
window.location.pathname
, thus triggering the hashchange event. (see step 3)window.location.pathname
after a hash (#). For example, Google crawls http://www.domain.com/about-us.aspx but when a user visits the page, they're redirected to http://www.domain.com/#/about-us.aspxThis way, users without Javascript will have a full-blown (semi-good-looking) website, Google will crawl all of the pages without any issues, but users with Javascript will always stay on the homepage - and the cool concept of having a Web App rather than a Web Site will be accomplished.
您是否也考虑过使用 HTML5 历史会话管理?
这样您就不必在较新的浏览器中使用哈希值,这样用户就不会注意到一件事。
有点简单,你会做这样的事情:
编辑:更新的例子。
Have you also considered to use the HTML5 history session management?
This way you don't have to use hashes in newer browsers and that way the user won't notice a thing.
A bit simplified you would do something like this:
EDIT: updated example.
使用 jQuery BBQ 并使用页面顶部的 js 函数来检查是否存在有效的哈希值,如果存在,则重定向到该页面。
Use jQuery BBQ and use a js function at the top of your pages to check if there is a valid hash, if so, redirect to the page.