runemadsen / Backbone-With-Server-Side-Rendering

An example of using backbone.js models, collections and view with HTML rendered from Sinatra/Datamapper.
16 stars 1 forks source link

Backbone with server side rendering

Backbone.js is a great tool for organizing your javascript code into models, collections and views, without tying your data to the DOM elements. However, most tutorials show how to render the HTML only via Backbone (client-side), which means that none of your content is crawled by search engines. This is possibly a major problem if you're not making an app hidden behind an authentication system.

This is a small example app written in Ruby / Sinatra that shows how to render your initial page with your Sinatra models (here using Datamapper YAML), and then handle events and DOM updates with Backbone.

The app renders HTML and create corresponding Backbone models, passing in the already existing DOM element.

Feel free to fork and make changes.