Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm working on an application that implements navigation based on hashchange events. Content is mostly loaded through ajax calls after hash changes (and displayed by DOM injections).

From a SEO perspective - are search engines able to index this injected content?
Are search engines able to follow my hash links (e.x. href="#page=1")?

If not - any workarounds besides having static content in my pages just for SEO reasons?

Thx

I found some similar threads on SO, but didn't find any satisfying answers, so forgive me to ask again.

share|improve this question

migrated from stackoverflow.com Jul 21 '12 at 16:02

This question came from our site for professional and enthusiast programmers.

add comment

5 Answers 5

While there are search engines that support crawling of ajax content, traditional urls and static page content are still more reliable for search engine visibility.

When a significant (large) portion of a page needs to be reloaded, it is usually desirable that ajax content be crawlable. In such cases, however, a redirect would usually be a viable (but undesirable) alternative.

I would suggest to initially code the page such that it redirects when large/significant portions of the page has to be reloaded (Step1). Meaning, us an anchor with a traditional url <a href="/page/1"> (or something similar) rather than <a href="#page=1">.

Afterwards, write up javascript (jQuery) to intercept redirection and use ajax to reload the portion of the page that would change if the page redirected(Step2).

<a id="page1" href="/page/1">Page 1</a>
<script>
    $("#page1").click(function () {

        /*
         * Perform ajax here to replace a portion of the page.
         */

        return false;    // prevent redirection
    });
</script>

The first step results in webpages with static content and traditional urls that work even without javascript while the second step makes the webpage dynamic (avoids static content).

share|improve this answer
add comment

To complete legoscia's answer (http://stackoverflow.com/a/11582278/1518423), you could use a headless browser library on the server side to give static html to the google bot.

Because you make heavy use of ajax it seems that you like javascript, so here is a javascript headless browser usable from node.js: http://zombie.labnotes.org/

Hope this is working for you, have fun!

share|improve this answer
add comment

are search engines able to index this injected content?

Ans - Yes & No.

No: If you inject the content by just changing the hashtag, then no the crawler won't be able to index the content. These normal hashtags were meant for same page navigation(much before the advent of AJAX) and not for changing the state of the page. So, in order to prevent re-indexing of the same pages several times, the crawlers were intentionally programmed to ignore everything after the hashtag in the url.

Yes: you have two work-arounds:

As far as SEO is concerned, both the work-arounds/solutions work equally well if implemented correctly. But which of the two is better apart from SEO is another discussion.

share|improve this answer
add comment

It's possible to enable Google to follow your hash links, but it takes some server-side changes.

share|improve this answer
add comment

https://github.com/balupton/history.js/wiki/Intelligent-State-Handling

^ Goes into the pros AND CONS of hashed and hasbhangs URLs and provides alternative solutions

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.