6

Why do we need to use a JS MVC framework(backbone) if we are already using a backend MVC framework(e.g Django or ROR). I can't understand the concept of two MVC frameworks and how they fit together. I thought all front-end related files or logic(html, css, js) come under the views component of the back-end framework. Can someone explain this in simpler terms?

jaykumarark
  • 2,359
  • 6
  • 35
  • 53

4 Answers4

9

Backbone lies in the client [browser], in order to have fast interaction and experience. This way you can take advantage of real-time communication via websockets, or LocalStorage for example.

Using a client MVC [MVVM better, in Backbone's case] implies that you just supply a RESTful set of resource from the server [which you can reuse in many other context], and not a full HTML generation stack.

Said that, client side MVC is closer to desktop/mobile UI-oriented MVC implementations [see Cocoa / iOS] than to web-oriented MVC [Symfony, Django, RoR...].

moonwave99
  • 21,957
  • 3
  • 43
  • 64
  • So in a way, django or RoR are there to serve only data via JSON APIs right? Hence, when a user requests or visits a website for the first time, all rendering part(templates, html, css, etc) are cached and stored locally and they change layouts(front-end template manipulation) depending on the url's(i.e a another page data) requested. Is this correct? – jaykumarark Dec 12 '12 at 11:29
  • Exactly : )) You may end rendering stuff from the server due to accessibility or SEO needs, but yeah you got it. – moonwave99 Dec 12 '12 at 11:32
  • Thanks for clarifying that. :) Can you suggest some good resources where I can create apps using backbone and django? I would rather build something and learn instead of going through tutorials. – jaykumarark Dec 12 '12 at 11:46
  • 1
    I don't use django, but [here](https://github.com/addyosmani/todomvc) you can find a compendium of popular js MVC framework, and [this](https://github.com/af/djangbone) seems an useful resource for what you need. – moonwave99 Dec 12 '12 at 11:51
1

It's mostly because of scalability, every MV* frameworks allows You to make modular code. To give users high experience by using websites, JS code and some fireworks are necessary. JavaScript gives also posibility to relieve backend side from unnecessary computations and because of these simple facts and the scale of currently made websites (huge amount of modules on backend and on frontend side), such MV* JavaScripts frameworks are made and becomes more and more popular.

0

You may want to look at this post Why use MVVM?

I have been using MVVM and have found it very useful for the front end. Rendering is much quicker and smoother and view-model binding is done on the client-side.

Community
  • 1
  • 1
tjhack
  • 1,022
  • 3
  • 20
  • 43
0

It seems like one of the reasons these JavaScript MVC frameworks started popping was in an effort to to bring some structure to client side JavaScript code. JavaScript has been used more and more in web apps in recent years because it enhances the client side experience so much but when you keep adding more and more, it can quickly become a big cobbled mess of spaghetti code. If you've ever inherited a web app that has tons of JavaScript, you know it can take a loooong time to sort through all the callbacks, functions, DOM manipulation, etc. that is going on just to to grasp how to app works and is tied together. It can be really messy. These JavaScript MVC frameworks help organize and bring structure too all this code so it doesn't get out of control.

Brady Holt
  • 2,844
  • 1
  • 28
  • 34