2
votes

I am currently working on a new Java project which relies on Spring MVC architecture (classical front controller-> dispatcher-> models and jsp views). However, as most of our views need Ajax dynamicity (jQuery), I am willing to use Require.js and Backbone.js frameworks mainly to structure the JavaScript code.

The problem is that, since my application is not SPA, I will have to load the js resources for each page request therefore losing state in JavaScript. That means that I will somehow have to let alone the Router and Model capabilities of Backbone which make no sense to that effect.

In that case, would it still be necessary to use Backbone in such a scenario? Is Require.js advised in such an architecture? Or will I be better off giving up these two technologies which are a perfect fit for SPA mainly. Has anybody had experience with it (off-SPA)?

Thanks a bunch, Jimmy

1
What logic will your app need on the client-side? Why are you considering using Backbone?James
Actually the view components will all be in jQuery (UI, plugins,...) no matter the logic. I am considering using Backbone because I've made a couple of entreprise applications these last years using js MVC frameworks such as JavaScript MVC, Backbone.js and SproutCore. But I wonder if I'll be able to fit Backbone in a non single page application (=thick server architecture) for the only purpose of structuring my JavaScript code and if it's not too much overhead using it.Jimmy Luis
I don't think it's worth it. You can maintain a JavaScript codebase without using Backbone. Then again, Backbone is pretty tiny, so if you find yourself writing JS that could fit in the MVC paradigm, then maybe Backbone is okay.James

1 Answers

1
votes

I have been using Backbone and require on a Spring MVC app for a while now. while the Spring controller returns the view, the backbone router is the one that takes care of starting the right backbone views, which inside of them I handle a lot of JavaScript code like validations, popup saving and fetching data etc. While this kind of architecture is hybrid I think it worth's the effort. insert in the header of your htmls the same call for the require main file, so you will have only a js line in your HTML files. then inside of main start your backbone routers, you will perhaps need to add #+something in your urls in order to have the backbone ruter(s) to work.