Bot友好的Ajax页面

I'm trying to code a seo friendly ajax portfolio right now. My goal is to provide javascript effects to users and normal html to bots/users without js.

Files:

  • index.php (starting point of my program)
  • aboutme.php (contains html code for "about me")
  • contact.php (contains html code for "contact")

The idea:

User visits index.php and clicks on "About me" -> loading animation appears -> aboutme.php gets loaded with ajax -> history.pushstate rewrites the url to aboutme.php.

-> When the user shares the current website url on fb/twitter/g+ the bots will get the correct title, body etc., as it is the normal html page without any javascript.

But my problem is: If other users open that page, they see directly the content. But I want to show them a loading animation first until the data got loaded with ajax (similar as they click on a link).

How can I achieve such an approach? Thank you very much!

Best way to do this, create a javascript file. Write the link tag into "head" part. This will make the javascript file downloaded before content. Javascript shows the animation, but at the same time browser will be downloading the content already in the background. On "document ready" event, stop animation.

This will let bots to access the content directly. Because javascript won't work for them.

I think that it is not a problem at all, keep your href of links as usual, then using JavaScript or jQuery change the default behavior of clicking link to load the linked contents with ajax.

I've always thought this is more effort than its worth(generally), but to answer your question:

index.php, aboutme.php, contect.php should deliver full html. certain links should have js event handlers intercept the click, and instead of loading aboutme.php, they load aboutme-content-only.php in the background. then update the dom and push state etc...

this way the site can easily degrade for those users who are first time visitors, as well as those whose browsers dont support push state or javascript.