要hashbang或不hashbang? [英] To hashbang or not to hashbang?

查看:366
本文介绍了要hashbang或不hashbang?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个新的网站,我想利用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.

现在我们现有的网站已经跻身pretty的高,所以我也想保持谷歌开心。我一直在阅读使Ajax应用程序抓取通过谷歌和理解,我必须通过的 _escaped_fragment _ 以提供履带相同的内容。

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_.

问题
我想用开发这个网站的一把umbraco 它已经提供SEO友好的URL。

The problem
I want to develop this website using Umbraco which already provides SEO-friendly URLs. i.e.

  • http://www.domain.com/about-us.aspx
  • http://www.domain.com/about-us/our-team.aspx

但问题是,我没有implemeting一个简单的方法 _escaped_fragment _ 没有黑客的一把umbraco核心(至少这是我的知识),并使用该解决方案(回答)我已经发布下方也将保持没有JavaScript的用户高兴。双赢局面?你告诉我! =)

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! =)

更新
有谁认为谷歌不再使用的 _escaped_fragment _ 方式,并建议该被排除在外的答案从另一个用户昨日(现已删除)。这是真的?谷歌是否会实际运行AJAX看的内容?

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

推荐答案

我从 @Daniel Pryden的注释服用建议和张贴此作为一个答案吧。

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.

  1. 拦截的网页上使用jQuery和 window.location.pathname ,从而引发hashchange事件之前所有的内部连接prePEND哈希(#)。 (见第3步)
  2. 添加所有网页上的一个JavaScript重定向除了网页重定向网页回到主页,但一个哈希(#)后追加 window.location.pathname 。例如,谷歌抓取 http://www.domain.com/about-us.aspx 但当用户访问该网页,他们重定向到 http://www.domain.com/#/about-us.aspx
  3. 在网页,使用jQuery烧烤或类似的插件来侦听hashchange事件包括何时,这样可以加载页面加载动态内容。一把umbraco可以配置为服务于基于该请求是否是一个AJAX的一个或不部分或全部网页内容。
  1. Intercept all internal links on the homepage using jQuery and prepend a hash (#) before the window.location.pathname, thus triggering the hashchange event. (see step 3)
  2. Add a javascript redirect on all pages apart from the homepage to redirect pages back to the homepage, but append the 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.aspx
  3. On the homepage, use jQuery BBQ or a similar plugin to listen for the hashchange event including when the page loads so that dynamic content can be loaded. Umbraco can be configured to serve partial or full page content based on whether the request is an AJAX one or not.

这样的话,没有JavaScript的用户将有一个全面的(半好看)的网站,谷歌会爬,没有任何问题,所有的页面,但用户使用Javascript将永远留在网页上 - 和凉爽的概念有一个Web应用程序,而不是一个网站,将完成。

This 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.

这篇关于要hashbang或不hashbang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆