I’m using Backbone with a RESTful backend (PHP). My question is to do with the initialisation of a collection after page load.
Backbone can load content from a remote source upon page load, but it seems a little wasteful to have another HTTP request for content which the PHP could of written into the page on first load.
I have mixed feelings about embedding the model data because it would require me to have two strategies to update the underlying collection.
Just wanted to see what other people thought.
Hope I’ve made sense.
Cheers,
Pete
The Backbone documentation recommends that you embed any data that is required on page start as data in the actual HTML, and only use the fetch methods on collections when you don’t specifically need the data on page start or are using some sort of lazy loading.
To steal the example from the documentation, you’d embed something like this in your PHP/HTML:
Forgive me if that’s incorrect PHP syntax, I haven’t used PHP for years.