2

I am experimenting with Angularjs and I really like what I have seen so far. However, one thing looks strange to me: As far as I can tell, Angular requires at least 2 requests for every dynamic view created: The first for the document and the second for data using $http service. That seems to be an incredible disadvantage for the following reasons:

  • network latency is doubled
  • the user can't see anything useful until the response to second request is preocessed

Imagine a page with a dynamicly created list of items. The first request pulls the document, the second gets the data to be dsiplayed. The user will end up with an empty list for a short period of time until the response to the second request is processed.

While it is possible to not show the list until the data is complete it is clear that the user experience will suffer from the doubled network latency. I see this as a major disadvantage over server side frameworks that deliver a document that initially contains the data.

Do I miss something here or is this a limitation 'by design'?

Darkspirit
  • 199
  • 3
  • 12
  • You can include the data initially in the document using [ng-init](http://docs.angularjs.org/api/ng.directive:ngInit) – noj Aug 05 '13 at 11:51
  • 1
    You are right. This is with any client side frameworks like angular, and is an acceptable practice. Angular caches the templates (document fragments) so that it does not have to make the request again for that in a SPA. This very well mitigates the problem to an extent – Chandermani Aug 05 '13 at 11:53
  • You can easily preload view as described here: http://stackoverflow.com/q/12346690/1418796 – pkozlowski.opensource Aug 05 '13 at 11:54
  • @jonnyynnoj i don't think, ng-init can help here, as the data needs to be there before ng-init can work on it, so it should be part of the script or model data returned from server. – Chandermani Aug 05 '13 at 11:57
  • Thx for the useful input so far. I was thinking about using a lean server side framework like Spring MVC to service document requests and add initial values on some pages. ng-init may be used for that. Unfortunately this leads to the usage of an MVC framework on the server- and another one on the client-side. Seems like a tradeoff between mixing server- and client side frameworks vs. accepting doubled network latency. – Darkspirit Aug 05 '13 at 12:21

0 Answers0