Skip to content Skip to sidebar Skip to footer

Inject Content/HTML Without Altering The DOM

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

Solution 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.


Solution 2:

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.


Solution 3:

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.


Solution 4:

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.


Post a Comment for "Inject Content/HTML Without Altering The DOM"