Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone recommends inserting all models when the page is generated on the server side

I'm a noob with backbone. Came across this advice following Addy Osmani's Book:

Can somebody please help me understand this? If the server is pushing the models as part of page generation (say through JSP) how can model data end up in a backbone model on the client side?

I can understand HTML templating and dynamic insertion of data through <% %> tags from the server, but how to set up a backbone model? Unless it is fetched from the client itself?

Following is the excerpt from the book:

The Backbone documentation recommends inserting all models when the page is generated on the server side, rather than fetching them from the client side once the page is loaded. Since this chapter is trying to give you a more complete picture of how to communicate with a server, we will go ahead and ignore that recommendation.

like image 328
user1800556 Avatar asked Jan 25 '26 00:01

user1800556


1 Answers

Please ignore that paragraph.

I've been developing backbone apps for more than an year and haven't seen such thing in the docs or came across such a scenario.

Backbone.js docs starts with:

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface (emphasis mine).

Further quotes:

A Model manages an internal table of data attributes, and triggers "change" events when any of its data is modified. Models handle syncing data with a persistence layer — usually a REST API with a backing database.

and further from API-integration:

Backbone is pre-configured to sync with a RESTful API.

No, The Backbone documentation doesn't particularly recommend crunching HTML and inserting all models on the server side.

If you look at the way the router is designed, you'll see it's primarily designed for SPA's (Singpe Page Applications) based on hash changes.

And well, there is no html coming from server at all when we talk about hybrid applications.

So ignore that comment without worries :) .

like image 106
T J Avatar answered Jan 27 '26 15:01

T J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!