0
votes

The Case:

One page app that display first time all items.(Use backbone.js + some mvc framework like rails)

What should index action render or how its should be build (if have some good article about that or/and live example please add it)?

Option 1 - (Problem: a. 2 HTTP calls b. more slow render):

a. index action render index view without data

b. call to getData action that send json with data and backbone insert them to models etc..

Option 2 - (Problem: a. 2 HTTP calls):

a. index action render index view with data

b. (only for sync backbone) call to getData action that send json with data and backbone insert them to models etc..

Option 3:

a. index action render index view with data

b. backbone view update the models etc..

thanks

1

1 Answers

1
votes

I think your 3 options are overlapping a little bit. My proposal would be a combination of 1 and 3, create one view to manage your models, collection, data:

  1. Connect your model/collection events like reset, add, change, ... to appropriate handlers in your intialize function
  2. Render index without data in your initialize function
  3. Fetch data for index, which works asynchronous, incoming data will be handled by event handlers (see a) in your intialize function

Pro: Users will see page immediately, data will be displayed automatically, ass soon as arrived from the servers, no manual intervention necessary.

This article might help for initalizing an application.

And I would recommend to wrap your models into separate Backbone sub views; but thats not absolutely required to answer your questions, just best practice :-). Some details on this topic can be found here.