Store vs Making requests on the go

AlbertClinton

i'm implementing an api for Q&A in my portal, and now i have 2 options:

  1. hard code the categories on the the html, and only when the category component is opened (the component will be an expansion-panel) the questions will be loaded from the api, also using requests to make an search by keyword;
  2. get all the questions and it's categories from the api right from the beginning and putting it in a rxjs store, listing and making the search mechanism in the component;

witch of those will be better for performance and why?

opel

Both options may be valid, depending on amount of data you fetch.

  1. hard code the categories on the the html, and only when the category component is opened (the component will be an expansion-panel) the questions will be loaded from the api, also using requests to make an search by keyword;

Categories do not have to be hard-coded; they can be retrieved from a remote store to be populated in your page. But whether or not you hard-code your categories, loading a category's questions on expansion (lazy loading) is a good strategy. Also, having huge amount of questions per category being loaded, you can implement pagination or virtual scrolling to address performance issues. In sum, combining lazy loading and pagination (or virtual scrolling) strategies should have good implications on performance. On top of all that, your search api should also perform well (since it filters out questions from other categories and from other pages inside current category.

  1. get all the questions and it's categories from the api right from the beginning and putting it in a rxjs store, listing and making the search mechanism in the component;

Storing inside rxjs's store is not required, since your questions' state is not to be changed. A service may be sufficient. As for performance, loading a lot of questions may result in bad performance. But more important, such strategy makes you app "frozen" (at least until the next time client refreshes browser).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related