Reputation: 33
Scenario:
I'm building a web app using angularjs. I have an api that connects to my database.
For example, if I have a page that uses data from my database. Which is the best way to go about doing this?
Way One
GET request for all data
var array = http.get( find all );
When I need specific queries
var another-array = http.get( find by query );
Way Two
GET request for all data
var array = http.get( find all );
When I need specific queries
for(loop through array to find data);
Somewhat related question, also the reason I'm tied between the two options, but what is the general rule of thumb with how many http.get() I should be making for a web page before it slows operations down too much.
Upvotes: 1
Views: 49
Reputation: 16226
It depends.
If your dataset is very small, Find All and Loop Through (way two) is better. You can "find all data" once and store that data in cache (global variable or browser storage). In this way, no time will be wasted on HTTP request/response.
If your dataset is very big, Find by Query (way one) is better, and you need to avoid "find all data" operation (unless user do want to check all data). When the dataset is very big, "find all data" operation and data-transfer will be very slow.
When Find by Query is used, to improve the performance, you can store each query result in cache, so that when the same query is made next time, you don't need to make request again.
For your second question: "how many http.get() I should be making for a web page before it slows operations down too much.", my suggestion is: define your oldest supported browser, make experiment and check the max concurrent http request number.
Upvotes: 2