注入内容/ HTML而不改变DOM [英] Inject content/HTML without altering the DOM

查看:89
本文介绍了注入内容/ HTML而不改变DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑#2



我可以从Google支持小组找到答案我的答案低于这个问题。



编辑#1



我认为这是一个比技术问题更多的SEO问题(尽管它在一定程度上是技术性的),所以我会发现别的地方,当我有东西分享






让我开始说我不是jQuery / JavaScript专家,所以到一些你这个问题可能听起来很笨拙。



我需要将内容/ HTML注入我的一个页面,但不改变DOM。注意我说INJECT不是REPLACE或ADD。这是因为SEO的原因,因为这个内容不被搜索蜘蛛索引。



另一位开发人员实施的当前解决方案是创建一堆图像与文本,所以现在这个网站只有60个HTTP请求。是的,



无论如何,我认为解决方案是通过包含该内容的JavaScript文件在页面上注入此内容,在我的标记中第一页只有一个< script src =js / testimonials.js>< / script> ,浏览器就可以执行这个文件显示其中的内容,而搜索蜘蛛将无法抓取该内容,因为它是一个JavaScript文件。



我试过jQuery的 .html(); 方法,但是当然,JS文件中的HTML被放置在实际页面上,从而使该内容可由搜索蜘蛛索引。这是我最初的想法,但这是不正确的。在这个问题下面阅读我的答案。



这是我试过的:

  $(function(){
$('。testimonials')。html('test');
});

我已经无法在SO和网络上找到这个解决方案。 / p>

非常感谢任何帮助完成这一点。



提前感谢

解决方案

搜索很久以后,我终于从Google支持小组自己找到了这个页面: Google Site Search可以在我的网页上搜索JavaScript内容吗?



这正是他们在该页面上所说的...简短的答案:不,它不能对JavaScript内容的内容进行索引:



Google自定义搜索不能对JavaScript中包含的内容进行索引。确保网页可以由Google编入索引的一般规则是确保所有需要编入索引的文本都可以在文本中显示,基于浏览器或关闭JavaScript的浏览器。



所以我的初始假设是正确的。



编辑:Google自定义搜索是您放入网站的搜索服务,不是www.google .COM。不过,我认为Google不会使用两个独立的引擎,一个用于Custome Search,另一个用于www.google.com。但是,这只是一个假设。



-



另一方面我错了: DOM没有变化Ed Heal是对的,当浏览器读取JavaScript文件的内容时,DOM 更改。但是再次,即使这样,内容也不会被搜索蜘蛛索引。



svidgen指出一些有趣的东西,隐藏。我没有想过。



阅读Google的隐藏例子后,...:


  1. 向搜索引擎提供HTML文本页面,同时向用户显示一页图片或Flash页面

  2. 只有当用户代理请求时,才将文本或关键字插入页面该页面是搜索引擎,而不是人类访问者

...我的解决方案是通过JavaScript和那些没有JS的访客就不会看到这些内容,因为我们认为这些内容不是页面核心内容的一部分,它们只是内容增强器。该页面的主要信息已经在他们获得推荐的时候已经说过了,所以没有内容策略的伤害。



svidgen提到的另一件事情听起来很有趣的是在执行用户操作后获取内容,这很有意义,肯定会考虑你的建议。



如果我有更多的信息,我一定会更新这个帖子。



每个人都提出非常有价值的评论/意见,让所有人都投票。



感谢大家的帮助!非常感谢。


EDIT #2

I was able to find an answer from Google Support, read my answer below this question.

EDIT #1

I think this is more an SEO question than a technical question (although it is technical to some extent), so I will find out somewhere else and post the answer here when I have something to share.


Let me start by saying that I'm no jQuery/JavaScript expert, so to some of you this question may sound dumb.

I need to 'inject' content/HTML into one of my pages but without altering the DOM. Note that I said INJECT not REPLACE or ADD. This is for SEO reasons since this content is not to be indexed by search spiders.

The current solution implemented by another developer was to create a bunch of images with the text, so right now the site has more than 60 HTTP requests just for that mere section. Yeah.

Anyway, I'm thinking that the solution is to inject this content on the page via a JavaScript file that contains that content, that way in the markup of my page I only have a <script src="js/testimonials.js"></script> for example, the browsers will be able to execute this file and display the content in it, while the search spiders will not be able to crawl that content since it's in a JavaScript file.

I've tried jQuery's .html(); method but of course the HTML in the JS file gets placed on the actual page thus making that content indexable by search spiders. That was my initial thought, but this is incorrect. Read my answer below this question.

This is what I tried:

$(function () {
  $('.testimonials').html('test');
});

I've been unable to find a solution for this around here in SO and around the web.

Any help to accomplish this is greatly appreciated.

Thanks in advance,

解决方案

After searching for a long time I finally found this page from Google Support themselves: Can Google Site Search index JavaScript content on my pages?

This is exactly what they say in that page... short answer: No, it cannot index content inside JavaScript:

"Google Custom Search can't index content contained in JavaScript. The general rule for making sure that a web page can be indexed by Google is to ensure that all of the text that needs to be indexed is visible in a text-based browser, or a browser with JavaScript turned off."

So my initial assumption was right.

EDIT : "Google Custom Search" is the search service you put in your website, it's not www.google.com. However, I would assume that Google wouldn't use two separate engines, one for Custome Search and another one for www.google.com. But yes, that's just an assumption.

--

On the other hand I was wrong about something: DOM not getting changed. Ed Heal was right, the DOM is altered when the content from the JavaScript file is read by the browser. But again, even after this the content will not be indexed by search spiders.

svidgen pointed out something interesting, 'cloaking'. I hadn't thought of that.

After reading Google's examples of cloaking...:

  1. Serving a page of HTML text to search engines, while showing a page of images or Flash to users
  2. Inserting text or keywords into a page only when the User-agent requesting the page is a search engine, not a human visitor

...the solution I have is to just serve the testimonials via JavaScript and those visitors without JS just won't see that content, which is fine by us since the testimonials are not part of the core content of the page, they're only content enhancers. The main message of that page has already been said by the time they get to the testimonials, so no hurt in the content strategy.

Another thing that svidgen mentions that sounds very interesting is having the content fetched after a user-action is performed, that makes a lot sense, will certainly consider your suggestion.

If I have anymore information about this, I will certainly update this post with it.

Gave everyone an up-vote since everyone made very valuable comments/opinions.

Thanks all for your help! Greatly appreciated.

这篇关于注入内容/ HTML而不改变DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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