As some of you may know, Google is now crawling AJAX. The implementation is by far something elegant, but at least it still applies to Yahoo and Bing AFAIK.
Context: My site is driven by Wordpress & HTML5. An Custom Post Type has tree types of content, and the contents of these are driven by AJAX. The solution I came for not using hashbangs (#!) until fully understand how to implement them is rather "risqué". Every link as HREF linking to *site.com/article-one/?tab=first_tab*, that shows only the contents of the selected tab (<div>Content...</div>
). Like this:
<a href="http://site.com/article-one/?tab=first_tab" data-tab="first_tab">This First Tab</a>
As you may note, data-tab is the value that JavaScript sends with AJAX Get, that gets the related content and renders inside a container. At the other side, the server gets the variable and does a <?php get_template_part('tab-first-tab'); ?>
to deliver the content.
About the risqué, well, I can see that Google and other search engines will fetch *http://site.com/article-one/?tab=first_tab* instead of http://site.com/article-one/, making users come to that URL instead of showing the home page with the tab content selected automatically.
The problem now is the implementation to avoid that.
Hashbang: From what I learned, I should do this.
- HREF should become
site.com/article-one/#!first-tab
- JS should extract the "first-tab" of the href and pass it out to $_GET (just for the sake of not using "data-tab").
- JS should change the URL to
site.com/article-one/#!first-tab
- JS should detect if the URL has
#!first-tab
, and show the selected tab instead of the default one.
Now, for the server-side implementation, here is where I'm kind lost in the woods.
- How Wordpress will handle
site.com/article-one/?_escaped_fragment_=first-tab
? - Do I have to change something in .htaccess?
- What should have the HTML snapshot? My guess is all the site, but with the requested tab showing, instead of showing only the content.
I think that I can separate what Wordpress will handle when it detects the _escaped_fragment_. If is requested, like by Google, it will show all the content plus the selected content, and if not, it's because AJAX is requesting it and will show only the content. That should be right?