开发者

Handlebars.js and SEO

开发者 https://www.devze.com 2023-04-11 15:32 出处:网络
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).

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 with开发者_如何学Cin 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.


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)


I do not know about Handlebar.js, but for my understanding SEO have some problem with CONTENT in JAVASCRIPT. Make sure your content is visible to Search Engine (use a spyder simulator for some test). Avoid spyder traps generally would be the way to go. Hope it could help you.


Search engines don't run JavaScript, so if you want to have your content indexed you'll need to render your templates on the server as well. You can use handlebars in Node (server-side JS) to render your template there when the page request comes from a spider. It's more work but it's possible. Github, google plus, and twitter all do something similar.


You could use Distal templates which puts the templates as part of the HTML for SEO.


See Spiderable for a temporary solution Meteor project (which uses Handlebars.js) uses for SEO purposes.

http://docs.meteor.com/#spiderable


Does the bot index the generated content (as intended) or only the source with the ugly javascript pseudo-variables?

Neither, because indexer bots don't run JavaScript and you don't serve up templates as HTML documents.

Build a site that works without JavaScript, then build on top of it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号