Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars.js and SEO

I have read a great deal of discussions about javascript templating and Search Engine Optimization. Still, I haven't found a satisfying answer to the question (either poorly-documented or outdated).

Currently I am looking into handlebars.js as a client-side template solution, because I love the possibility to create helper functions. But what about indexing for search engines? Does the bot index the generated content (as intended) or only the source with the ugly javascript pseudo-variables? I know that there are lots of threads going on about this matter but I feel that nobody does exactly know the answer.

If engines like Google would not index these templates properly, why would one bother using this for public websites?

Another question within this context: Is it possible to render Handlebar.js templates on server side and then present them onto the client side? Obviously to avoid all this SEO discussion.

like image 852
Maarten Avatar asked Oct 07 '11 09:10

Maarten


1 Answers

For dom crunching client side, most web bots (i.e. Google and others) don't interpret js on the fly and parse newly rendered content for indexing. Instead Google (and now Bing) support the 'Google Ajax Crawling Scheme' (https://developers.google.com/webmasters/ajax-crawling/docs/getting-started) - which basically states that IF you want js rendered dom content to be indexed (i.e. rendering ajax call results), you must be able to:

  1. Trigger the async js rendering via the url using hashbangs #! (i.e. http://www.mysite.com/#!my-state), and
  2. Be able to serve a prerendered dom snapshot of your site AFTER js modification on request.

If using a client side MVC framework like Backbone.js, or Spine - you will need to provide this service if you want your web app indexed.

Generally this means you intercept a request made by the web bot (explained on the link above), and scrape your side server side using a headless browser (i.e. QT + capybara-webkit, HtmlUnit, etc.), then deliver the generated dom back to the requesting bot.

I've started a gem to do this in ruby (now taking pull requests) at https://github.com/benkitzelman/google-ajax-crawler

It does this as rack middleware using capybara-webkit (and soon phantomjs)

like image 54
Ben Avatar answered Nov 13 '22 11:11

Ben