Mo’z Thinkz

Morriz

Just another idiot that wants to be heard…

Backbone everywhere

I finally put my newly built Node.js MVC stack on github! You can download it here: backbone-everywhere.

What’s so special about it? Here’s my list of exciting features:

  • Pages are rendered on the Node.js server by Backbone and jQuery.
  • All script resources are bundled by browserify and fileify,  uglified by uglify, and gzipped by connect-gzip for fast loading and deployment on other possible javascript environments.
  • The entire Backbone MVC stack works on the server, and is loaded in javascript enabled browsers to take over from there.
  • The app state is reflected in the url by means of HTML5’s pushState, or using hash notation when not supported.
  • The same app state is regained for non-javascript browsers pulling full requests from the server, so no worries about SEO!
  • All client / server communication is handled by socket.io (ajax is sooo 2009) and subscribed clients are updated with published models.
  • A JSON-RPC service listening to ‘/api’ requests, with an easy to build on service layer. Handy for non-web contexts such as mobile devices.
  • All data is persisted in Redis through an adaptation of mine of backbone-redis, enabling indexing, sorting and  foreign key lookups.

For me this is a whole new approach at engineering web applications, but I think I’ve managed to get a grip on it.
Not only that, it gave me a great impulse to reconnect with the pioneers of tomorrow. Because what I have done was build on top of the stuff from people with great vision.
Big shout out to the open source community, and the people willing and wanting to share. The sum of it’s parts will eventually overcome the current patent trolling paradigm.

What are you waiting for? Dig in!

4 Comments, Comment or Ping

  1. Cool, very interested in this topic. Are you aware of Capsule? How does this compare? https://github.com/andyet/capsule

  2. From taking a brief look at Capsule, it looks like its aim is to share the same model code from client into server, meaning things like validation only need to be written once.

    What backbone-everywhere is demo-ing is running the whole of Backbone.js within node.js, so not only are your models shared but so are your views and routers too. Using jsdom and jquery on the server means that your views can be stitched together on the server just as they would be on the client, meaning SEO for a single page app might actually be feasible! This is a huge win, but I’m not sure if this approach will be massively scalable.

  3. Tai-Jin Lee

    I have a question — why do you load the page as HTML from the server when you could just load it via JS? I understand that you’d want to load the page from the server when the user agent is googlebot etc, but otherwise there doesn’t seem to be a point in doing the work on the server side? I must be missing something.

    I’ve actually been looking into figuring out how to do server side rendering for backbone as well, but I think I’m only going to do it when it’s the google bot, and other search engine scrapers.

  4. You are mostly right. It exists mainly for non javascript enabled browsers, but this approach lends itself also for serving cached deep links, so the initial request is quick.

Reply to “Backbone everywhere”