Reusing backbone views/routes on the server when using Backbone.js pushstate for seo/bookmarking
Asked Answered
A

2

9

I'm doing some due diligence on backbone for a single page app and wonder if it is possible to re-use the same views/routes from the client on the server side, so that when google visits a pushstate URL, or it is accessed directly, the server can generate the exact same HTML that would be generated by backbone in the client.

It would be a pain to have to maintain two separate sets of views/routes, one on the client and one on the server. I have seen the backnode project on github however this seems to miss the point a bit and you end up having to write the same backbone router twice.

Just wondering how people are generally handling the case when using pushstate urls in backbone and needing to serve the same view from the server? Are people duplicating code or is there a better way?

Anthem answered 17/8, 2011 at 19:9 Comment(0)
T
5

I haven't tried this yet but these ideas using node.js and backbone might help:

http://andyet.net/blog/2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/

http://bennolan.com/2010/08/13/pushstate-and-nodejs.html

Basically the only way to make it so your not writing the same thing twice is to have both your node.js server and frontend client share the same routing/model code. If you are using something else on the server side (like Ruby) you would have to place node.js in front of your app server. Then make node.js proxy for new clients (push state and client js) and do actually rendering work for old/bot clients.

The other option is doing what jQuery Mobile does which is the Hijax method. The idea to make tons of HTML5 pages (you'll have to look at its routing to see).

And for completeness you should be aware of how google crawls AJAX: http://code.google.com/web/ajaxcrawling/docs/getting-started.html

Trueblood answered 1/9, 2011 at 13:9 Comment(2)
I just found idiotz.nl/2011/08/28/backbone-everywhere. I think this could be just what I am looking for, as he has got backbone working on server side so all views are rendered server side and spat out to the client, from there the client takes over, meaning the seo problem is solved.Anthem
Yeah there are so many nodejs frameworks now. I blogged about this (see my profile) and still not sure so I have been playing with express + backbone.js + persistence.Trueblood
L
0

This project does exactly what you are trying to do. It might interest you to check it out. https://github.com/developmentseed/bones

Lawmaker answered 7/1, 2013 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.