Googlebot 看不到 jquery 生成的内容
我使用 jQuery 通过 json 请求从数据库检索内容。然后,它将 HTML 中的通配符(如 %title%)替换为实际内容。这非常有效,这样我就可以在数据库中维护我的多语言文本,但 Googlebot 只能看到通配符,而不是实际内容。我知道 Googlebot 会看到没有 javascript 的页面,但是有办法解决这个问题吗?谢谢!
I use jQuery to retrieve content from the database with a json request. It then replaces a wildcard in the HTML (like %title%) with the actual content. This works great and this way I can maintain my multi-language texts in a database, but Googlebot only sees the wildcards, not the actual content. I know Googlebot sees pages without javascript, but is there a way to deal with this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在回答这个问题时,Google 似乎拥有一个几乎完全或功能齐全的 javascript 爬行机器人:
2009 年,Google 提出了一个使 AJAX 可爬行的解决方案:https://webmasters.googleblog.com/2009/10/proposal-for-making-ajax-crawlable.html
2015 年,Google 弃用了上述方法:https://webmasters.googleblog.com/2015/ 10/deprecating-our-ajax-crawling-scheme.html
我已成功构建了多个在 Google 网站站长工具中正确呈现的单页应用程序。
如果您想深入了解,网络上有很多资源:
Google appears to have a near-fully or fully functional javascript-crawling bot at the time of this answer:
In 2009 Google proposed a solution for making AJAX crawlable: https://webmasters.googleblog.com/2009/10/proposal-for-making-ajax-crawlable.html
In 2015 Google deprecated the above approach: https://webmasters.googleblog.com/2015/10/deprecating-our-ajax-crawling-scheme.html
I have successfully built multiple single page applications that are correctly rendered in Google's Webmaster tools.
There are lots of resources on the web if you want to dive deeper:
您应该向 Google 提供此文档彻底阅读。
它讨论了如何让 Googlebot 能够对以下内容建立索引:
#hashfragment
值的变化而变化的页面。#hashfragment
的页面。简而言之,您正在考虑添加“步骤 3”中讨论的
,并响应 服务器端通过一次性传回所有内容,否则客户端代码将在页面加载后生成。这些特殊请求实际上是 URL 中带有
?_escaped_fragment_=...
的请求,向服务器指示它应该将(我的话)所有最终演示文稿预先烘焙为 Googlebot 的单个响应。也就是说,由于您需要为这种特殊情况输出填充的内容,因此在一般情况下这样做可能会更好(避免需要处理 Google 的
_escaped_fragment_
请求),如果有必要的话,也许还有一种方法可以在页面加载后交换标记(例如,通过使用具有特定class
或id
的跨度来识别它们)。You should give this document at Google a thorough read.
It discusses how to enable Googlebot to index:
#hashfragment
values in the URL.#hashfragment
per se.In short, you're looking at adding the
<meta name="fragment" content="!">
as discussed in "step 3", and responding to special requests on the server-side by delivering back all the content all at once, that your client code otherwise would have generated after page load. These special requests are actually requests with?_escaped_fragment_=...
in the URL, indicating to the server that it should pre-bake (my words) all of the final presentation into a single response for the Googlebot.That said, since you'd be going through the effort of outputting filled in content for this special case, you may be better off doing that in your general case (avoiding the need to deal with Google's
_escaped_fragment_
requests), with perhaps still a way to swap out your markers after page load if necessary (e.g. through the use of spans with a certainclass
orid
for identifying them).Googlebot 显然不会渲染它下载的页面。这可能与其他搜索机器人也采用相同的行为。
您需要使用服务器端脚本或编译解决方案(有很多可供选择,包括 PHP、ASP.NET 等)。这样,您仍然可以保留动态和国际化功能,并且 Googlebot 会按照您想要的方式查看您的页面。或者至少对基本页面属性(例如您知道 Googlebot 正在评估的标题)执行此操作,并保持页面中不太重要部分的 jQuery 更新。
(不过说实话,在页面下载后使用 jQuery 替换令牌可能不是最有效的方法,尤其是当服务器端脚本如此简单且免费时)。
Googlebot obviously doesn't render the page that it downloads. This will probably be the same behavior that other search bots employ as well.
You need to use a server side scripting or compilation solution (there are plenty to choose from, including PHP, ASP.NET, etc). This way you still keep your dynamic and i18n features and Googlebot sees your page the way you intended. Or at least do this for fundamental page attributes like the Title that you know Googlebot is evaluating, and keep the jQuery updating for not so important parts of the page.
(To be honest though, using jQuery to replace tokens after the page has downloaded is probably not the most efficient way to do things, especially when server side scripting is so easy and free).