搜索引擎可以索引 JavaScript 生成的网页吗? [英] Can search engines index JavaScript generated web pages?

查看:49
本文介绍了搜索引擎可以索引 JavaScript 生成的网页吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 等搜索引擎可以索引 JavaScript 生成的网页吗?当您在由 JavaScript 生成的页面(例如使用 GWT)中右键单击并选择查看源代码时,您看不到动态生成的 HTML.我想,如果搜索引擎也看不到生成的 HTML,那么就没有太多可索引的,对吧?

Can search engines such as Google index JavaScript generated web pages? When you right click and select view source in a page that is generated by JavaScript (e.g using GWT) you do not see the dynamically generated HTML. I suppose that if a search engine also cannot see the generated HTML then there is not much to index, right?

推荐答案

您的怀疑是正确的 - 不能依赖 JS 生成的内容对搜索机器人可见.关闭 JS 的任何人也无法看到它 - 而且,上次我向我正在处理的站点添加了一些测试(这是一个大型的主流受众站点,每月有数十万个独特的访问者),大约 10% 的用户没有以任何形式运行 Javascript.这包括搜索机器人、禁用 JS 的 PC 浏览器、许多手机、使用屏幕阅读器的盲人……等等.

Your suspicion is correct - JS-generated content cannot be relied on to be visible to search bots. It also can't be seen by anyone with JS turned off - and, last time I added some tests to a site I was working on (which was a large, mainstream-audience site, with hundreds of thousands of unique vistors per month), approx 10% of users were not running Javascript in any form. That includes search bots, PC browsers with JS disabled, many mobiles, blind people using screenreaders... etc etc.

这就是为什么通过 JS 生成的内容(没有回退选项)是一个非常糟糕的主意.

This is why content generated via JS (with no fallback option) is a Really Bad Idea.

回到基础.首先,使用 bare-bones (X)HTML,按照类似 REST 的原则(至少在需要 POST 请求状态更改的范围内)创建您的网站.简单的语义标记,忘掉 CSS 和 Javascript.

Back to basics. First, create your site using bare-bones (X)HTML, on REST-like principles (at least to the extent of requiring POST requests for state changes). Simple semantic markup, and forget about CSS and Javascript.

第一步是做对,让您的整个网站(或尽可能多的网站)以这种方式为搜索机器人和类似 Lynx 的用户代理正常工作.

Step one is to get that right, and have your entire site (or as much of it as makes sense) working nicely this way for search bots and Lynx-like user agents.

然后添加一个视觉层:CSS/graphics/media 进行视觉润色,但不要显着改变您原来的 (X)HTML 标记;允许原始纯文本站点保持完整和正常运行.保持标记干净!

Then add a visual layer: CSS/graphics/media for visual polish, but don't significantly change your original (X)HTML markup; allow the original text-only site to stay intact and functioning. Keep your markup clean!

第三是添加一个行为层:Javascript (Ajax).使用支持 Ajax 的 JS 为用户/浏览器提供更快、更流畅、更好的体验……但仅限于那些用户.仍然欢迎没有 Javascript 的用户;搜索机器人、视障人士、许多手机等也是如此.

Third is to add a behavioural layer: Javascript (Ajax). Offer things that make the experience faster, smoother, nicer for users/browsers with Ajax-capable JS... but only those users. Users without Javascript are still welcome; and so are search bots, the visually impaired, many mobiles, etc.

这在网页设计界称为渐进增强.这样做,您的网站就会以某种合理的形式为所有人服务.

This is called progressive enhancement in web design circles. Do it this way and your site works, in some reasonable form, for everyone.

这篇关于搜索引擎可以索引 JavaScript 生成的网页吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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