SEO Myths #6

It's not worth using AJAX, because it can't be spidered by search engines

There is a way to enable search engines to read everything on your AJAX-enabled site. This answer is going to get technical, so if code is not your thing, you have been warned!

You need to set up your site in the right way - the accessible way - using progressive enhancement. This way, search engines will be happy, whether you're using AJAX to load some of the content or not.

In practice, you need to ensure that where a call is made using AJAX to update the page, if you have Javascript turned off, you will still be taken to a page where the same content is shown.

The basics of doing this is to use onclick events with 'return: false;' rather than putting your Javascript call in an href.

So for instance if you currently have a link which looks like this:

<a href="javascript:showarticle(42);">Show next article</a>

It would change to this:

<a href="show_article.php?article=42" onclick="javascript:showarticle(42); return false;">Show next article</a>

If you have Javascript turned on, the 'showarticle' function is called and the 'return false' stops the browser following the link.

If you do not have Javascript turned on - i.e. if you're a search engine spider, or you use accessibility equipment that can't cope with complicated Javascript, such as some of the older screen readers - you get sent through to the page show_article.php and that page can show the content, rather than loading it in through Javascript.

While this means making some more pages, if you're sensible about the way you structure your server-side code (whether it's PHP, .Net or any other language), it shouldn't cause much extra coding as you'll be mainly re-using server side code that you've all ready written to output the code for the AJAX calls.

Creating your site this way gets you two benefits: better search engine rankings because the spiders can find your content, and better accessibility, which as well as being a very good thing generally, may be a requirement depending on your local business laws.


More SEO Myths