Anatolii Humennyi
Anatolii Humennyi

Reputation: 1856

Load view with populated data in AngularJS

The problem:

AngularJS forces to split view from model and it's good. But we're experiencing the following downsides because of it: When a user loads our page a browser makes not 1, but 2 requests:

  1. First it loads view template (the first request)
  2. Then Angular services load data from a server (the second request)

And we have a bit slower load page speed.

The question:

Is it possible after first page loading load view with populated data and only then get data from a server when something must be changed on the page?

I tried to find something regarding it, but didn't find anything.

Upvotes: 0

Views: 48

Answers (2)

ezekielDFM
ezekielDFM

Reputation: 1977

The modular approach would be to break all the different components of the page that consume data into separate data requests, so that the interface can load in progressively as different data requests complete.

Additionally, you can load initial data, but then make some predictions on what the user will do next and lazy load additional data in the background.

Finally, you could store the previously loaded data in local storage (lots of modules out there you can utilize) so that it's pulled instantly upon the user's next visit. You would want to want to also add some sort of timestamp comparison on data in storage and on server to see if it has been updated.

Upvotes: 1

Michael
Michael

Reputation: 3104

You will have a lot more request as you have to load the Javascript and CSS libraries as well.

You can store your initial data in a service or the rootscope and just update the data when you need it. What's exactly your problem here?

Upvotes: 1

Related Questions