I am learning about backbone, and from the examples and tutorials I have gotten this impression:
GET /
returns the skeleton page with backbone and the view templates.REST API
to flesh out the page by GET
ting the data it needs and adding it into the DOM.This works, but it seems wasteful in terms of additional HTTP requests, and latency from the perspective of the end user (minimum two round-trips before the page is visible. Actually three in my case, since the API must first ask which widgets are available, and then fetch the details on any available widgets....).
Is there an established, standard method for getting around this? My current candidates are:
Is there an established way to do this? Is it situation-specific? I am using Node / JS / Express.
Update: I think I found a solution, possibly the "accepted" solution, in Backbone's documentation:
Here's an example using reset to bootstrap a collection during initial page load, in a Rails application.
<script> var Accounts = new Backbone.Collection; Accounts.reset(<%= @accounts.to_json %>); </script>
Calling
collection.reset()
without passing any models as arguments will empty the entire collection.