Warning: Declaration of Imbalance2_Walker_Nav_Menu::start_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array) in /var/www/zmolklife.com/lotrproject.com/blog/wp-content/themes/imbalance2/functions.php on line 0

Warning: Declaration of Imbalance2_Walker_Nav_Menu::end_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::end_lvl(&$output, $depth = 0, $args = Array) in /var/www/zmolklife.com/lotrproject.com/blog/wp-content/themes/imbalance2/functions.php on line 0
Enabling crawling of Ajax-generated content for Google | LotrProject Blog
Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/zmolklife.com/lotrproject.com/blog/wp-includes/post-template.php on line 259

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/zmolklife.com/lotrproject.com/blog/wp-includes/post-template.php on line 259

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/zmolklife.com/lotrproject.com/blog/wp-includes/post-template.php on line 259

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/zmolklife.com/lotrproject.com/blog/wp-includes/post-template.php on line 259

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/zmolklife.com/lotrproject.com/blog/wp-includes/post-template.php on line 259
the blog

Enabling crawling of Ajax-generated content for Google

Most of LotrProject consists of a single gigantic family tree with characters from Tolkien’s works, currently containing about 920 characters. Clicking on a character will reveal information associated with it in a nice popup info-box. Since I can not have all of this information generated directly when accessing the main page it is dynamically loaded with ajax.

Very nice solution but this will cause some issues with Google search. Google’s crawl robots may be clever but they do not yet detect content loaded through Ajax. Google hints that support for this may come in the future as they want to make the bots behave more similar to regular browsers. The lack of current support means only the main page will be indexed by Google.

Fortunately, Google provides a solution for this on this page. It requires a little bit of work but will fix the issue.

First you need to indicate that your webpage support ajax crawling. This is done by changing hashes on your page from for example

lotrproject.com/somepage.php#about

to

lotrproject.com/somepage.php#!about

The ! will tell Google your page support ajax crawling. What the robot will do is replace the ! with ?_escaped_fragment_ so that it look like this:

lotrproject.com/somepage.php#?_escaped_fragment_=about

and this is where it will look for a html snapshot of the page for it to crawl. This page should  only be for the bot to use and users of the site should be at the regular url.

Serving a html snapshot is very easy with PHP:

<?php if($_GET['_escaped_fragment_'] == 'about') {
// Serve your HTML snapshot of the about page here
} ?>

If you are using rewritten clean urls don’t forget to enable additional php parameters on the urls in your .htaccess file or it will not detect the added ?_escaped_fragments_ part. This can easily be done by adding [QSA] to the end of the line in your .htaccess file.

I hope this will prove useful for someone.

 

Show your love and donate
Updating and developing LotrProject takes many hours of work each month and hosting the site costs a lot of money. Please help keep this project up and running without advertisements and donate a small amount.

Comments

Leave a Reply