Here is the typical sequence of events when someone navigates to a page in my application:
- The user navigates to my application, including URL parameters and query strings.
- The server receives the request and generates the HTML
- On the client, AngularJS grabs any parameters and makes an AJAX call
- The resulting data is then bound
Personally, I find it a bit wasteful that this requires two hits to the server. It leads to a delay between the HTML being returned and the inputs being populated.
Am I missing something? Is there a way to avoid going back and forth the first time?
1
I don’t know the specifics of angular, but there is no reason to not insert any initial data into the page directly. In Fact backbone suggests doing exactly that. All you would have to do is put in your template something like this
<script>
var initial_data = {json with your data here};
</script>
Where you inject the json from whatever server side framework you are using.
1
The server receives the request and generates the HTML
One-page application should be a skeleton, some views and some models (MV*). I think is incorrect to say that, at the first call, the server generates the HTML. In fact, Angular, or backbone, or any other Javascript frameworks, they want to manipulate the DOM (and they do it very well).
The role of the server, and the first call is to response with a skeleton. From that moment on, the server job is to handle RESTful.
What I’m considering is that building hybrid Web Apps (where an ASP.NET application or PHP meet MV*) can be a little confusing, especially because probably these are generating a lot of HTML in their core.
So the potential of Angular.js (or…) is reduced (mixing both philosophies), just because on the server side, there are still many processes of transformation of the DOM, and the javascript framework is ready to handle this at 100%, but it does so merely in part.
3