谷歌搜索优化Ajax调用 [英] Google Search optimisation for ajax calls

查看:110
本文介绍了谷歌搜索优化Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网站有东西被频繁更新列表的页面。这个列表是通过调用通过JSONP服务器,获取JSON回来,将其转化成HTML创建。快速和光滑。

不幸的是,谷歌不能够索引它。关于如何得到这个根据谷歌的AJAX检索指南,我有点困惑,需要一些澄清和确认:

页需要只,正确执行规则的AJAX? 我现在有一个休息的URL如

<$p$p><$c$c>[site]/base/junkets/browse.aspx?page=1&rows=18&sidx=ScoreAll&sord=desc&callback=jsonp1295964163067

这将需要变成是这样的:

<$p$p><$c$c>[site]/base/junkets/browse.aspx#page=1&rows=18&sidx=ScoreAll&sord=desc&callback=jsonp1295964163067

当谷歌称它像这样

<$p$p><$c$c>[site]/base/junkets/browse.aspx#!page=1&rows=18&sidx=ScoreAll&sord=desc&callback=jsonp1295964163067

我会为客户提供HTML快照。

为什么要更换?以#? 创建HTML快照显得很繁琐。它是否足以只是起到简单的链接?在我来说,我会很高兴,如果谷歌将只指数事情页面。

解决方案

它看起来像你误解了AJAX检索指南。该#!符号是用来在链接的您的AJAX应用程序中的生活,而不是在服务的URL你的应用的新进行调用至。举例来说,如果我转到 example.com/app / 访问你的应用程序,那么你会做网页抓取,而不是通过链接到的例子。 COM / APP /#!页面= 1

现在,当Googlebot看到,而不是去 example.com/app /#该URL的链接,页面= 1 &ndash的!;这意味着印发 example.com/app / (回忆一下,散永远不会发送到服务器)和ndash的请求;它会要求 example.com/app /?_ escaped_fragment_ =页= 1 。如果 _escaped_fragment _ 是present一个请求,你知道返回内容的静态的HTML版本。

为什么是这一切的必要吗? Googlebot不会执行脚本(也不知道如何索引你的JSON对象),所以它没有办法知道哪些结束了在你的用户面前后,你的脚本运行和内容被加载。所以,你的服务器有做生产哪些用户在AJAXy版本最终看到的HTML版本的重任。

那么,什么是你的下一个步骤是什么?

第一,要么改变指向您的应用程序的链接,包括#!页= 1 (或其他),或添加&LT; META NAME =片段的内容=&GT!; 到您的应用程序的HTML。 (见href="http://$c$c.google.com/web/ajaxcrawling/docs/getting-started.html" rel="nofollow"> AJAX检索指南的

当用户改变页面(如果适用),你也应该更新哈希值,以反映当前页面。你可以简单地设置的location.hash ='#页=的 N 的!; ,但我建议你使用优秀的 jQuery的烧烤插件,以帮助您管理页面的哈希值。 (这样,你可以听对哈希如果用户手动更改它在地址栏中。)警告:BBQ(1.2.1)的目前发布的版本不支持AJAX抓取网址,但最新版本的Git的主(1.3 pre)呢,所以你需要的在这里抢。然后,只需设置AJAX抓取选项:

  $ param.fragment.ajaxCrawlable(真)。
 

,你将不得不一些服务器端逻辑添加到 example.com/app / 来检测presence 。对 _escaped_fragment _ 的查询字符串,然后返回页面的静态HTML版本,如果它的存在这是在创建HTML快照可能是有帮助的。这听起来像你可能想追求选项3.你也可以修改您的服务输出HTML除了JSON。

I have a page on my site which has a list of things which gets updated frequently. This list is created by calling the server via jsonp, getting json back and transforming it into html. Fast and slick.

Unfortunately, Google isn't able to index it. After reading up on how to get this done according to Google's AJAX crawling guide, I am bit confused and need some clarification and confirmation:

The ajax pages need to be implement the rules only, right? I currently have a rest url like

[site]/base/junkets/browse.aspx?page=1&rows=18&sidx=ScoreAll&sord=desc&callback=jsonp1295964163067

this would need to become something like:

[site]/base/junkets/browse.aspx#page=1&rows=18&sidx=ScoreAll&sord=desc&callback=jsonp1295964163067

And when google calls it like this

[site]/base/junkets/browse.aspx#!page=1&rows=18&sidx=ScoreAll&sord=desc&callback=jsonp1295964163067

I would have to deliver the html snapshot.

Why replace the ? with # ? Creating html snapshots seems very cumbersome. Would it suffice to just serve simple links? In my case I would be happy if google would only index the things pages.

解决方案

It looks like you've misunderstood the AJAX crawling guide. The #! notation is to be used on links to the page your AJAX application lives within, not on the URL of the service your appliction makes calls to. For example, if I access your app by going to example.com/app/, then you'd make page crawlable by instead linking to example.com/app/#!page=1.

Now when Googlebot sees that URL in a link, instead of going to example.com/app/#!page=1 – which means issuing a request for example.com/app/ (recall that the hash is never sent to the server) – it will request example.com/app/?_escaped_fragment_=page=1. If _escaped_fragment_ is present in a request, you know to return the static HTML version of your content.

Why is all of this necessary? Googlebot does not execute script (nor does it know how to index your JSON objects), so it has no way of knowing what ends up in front of your users after your scripts run and content is loaded. So, your server has to do the heavy lifting of producing a HTML version of what your users ultimately see in the AJAXy version.

So what are your next steps?

First, either change the links pointing to your application to include #!page=1 (or whatever), or add <meta name="fragment" content="!"> to your app's HTML. (See item 3 of the AJAX crawling guide.)

When the user changes pages (if this is applicable), you should also update the hash to reflect the current page. You could simply set location.hash='#!page=n';, but I'd recommend using the excellent jQuery BBQ plugin to help you manage the page's hash. (This way, you can listen to changes to the hash if the user manually changes it in the address bar.) Caveat: the currently released version of BBQ (1.2.1) does not support AJAX crawlable URLs, but the most recent version in the Git master (1.3pre) does, so you'll need to grab it here. Then, just set the AJAX crawlable option:

$.param.fragment.ajaxCrawlable(true);

Second, you'll have to add some server-side logic to example.com/app/ to detect the presence of _escaped_fragment_ in the query string, and return a static HTML version of the page if it's there. This is where Google's guidance on creating HTML snapshots might be helpful. It sounds like you might want to pursue option 3. You could also modify your service to output HTML in addition to JSON.

这篇关于谷歌搜索优化Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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