0

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,

Ricardo Zea
  • 10,053
  • 13
  • 76
  • 79

4 Answers4

1

You cannot "inject" HTML into the document without altering the DOM. A HTML document (web page) is a DOM as view by both browsers and spiders.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
  • Not really, seems it is possible using `innerHTML`. Just found this article [Can Google Really Access Content in JavaScript? Really?](http://moz.com/ugc/can-google-really-access-content-in-javascript-really). Hopefully someone else here in SO has more information. Thanks. – Ricardo Zea Mar 21 '14 at 20:37
  • 1
    My understanding is that if you can fake a JS engine on the spider the DOM will be altered. However if that requires user intervention *e.g. typing in stuff) then you can have one page with infinite DOMs to be indexed. So if and AJAX query or JS requires user input then that cannot be indexed. I hope this makes sense. But either way inserting stuff using `innerHTML` after the event will change the DOM – Ed Heal Mar 21 '14 at 20:48
1

If my understanding is correct in that "not altering the DOM" isn't really you're concern; but rather, hiding some content from JavaScript-executing crawlers.

My initial reaction: I'd posit that any content you're trying to hide from a crawler should be hidden because it's intended only for certain users. The solution there is easy: Only show it to signed in users. If that doesn't sound like a good solution, I'd suggest you reconsider whether you're at risk for being removed from rankings entirely. (See cloaking.)

However, if you want to cloak your content anyway, you probably need to postpone fetching it until a user-action is performed. Set it to load on scroll or on mousemouse.

svidgen
  • 13,744
  • 4
  • 33
  • 58
1

Have a robots.txt file which instructs not to SEO your page contents by a search bot. Yes!, the bad ones bypass this rule. But google crawler for example, would not index.

Also, you could have your testimonial page accessed after authentication. As an example, my gmail contents cannot be SEO or searched by other users.

Faiz Mohamed Haneef
  • 3,418
  • 4
  • 31
  • 41
0

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.

Ricardo Zea
  • 10,053
  • 13
  • 76
  • 79