How to deal with dynamic JSON data using AngularJS?

AngularJS: Load all data at once as JSON vs. using a database and only load parts. What is better?

  • I have to display products which are stored in an ERP on a webpage. The ERP can produce an XML or JSON file which would include all products. The webpage needs functions like pagination, sorting or filtering by attributes. At the moment I think the easiest way would be to just load the entire file in AngularJS and then iterate over all items and work with that. The number of products is limited to ~500. The reason why I think this is the easiest is because the client changes the information on a daily basis in this way I don't have to write an import / synchronization process for a database. But I am a bit worried about performance. Sorting, filtering, pagination etc. are all things that would be very fast with a database (probably MongoDB since the datastructure is quite simple). Can I expect serious performance problems? Is this doable? Or should I put a database between ERP and frontend that does the heavy lifting?

  • Answer:

    The only way to be sure is to test it out yourself, that is what I would do. The answer is very often, "it depends.. ". You say its around ~500 products, if each product only has a product name, then a database would be overkill. Angular is perfectly comfortable with that amount. But if each product got tons of properties and nested data, the file itself could be very large to even load on every pageload. So, it depends.. I would to this: Export the file from the ERP as JSON Create a boilerplate angular app Put the JSON file as a resource file Create a simple repeater and throw those objects out into the DOM Now you can easily experiment with filtering, sorting, pagination and so on. Test if the browser perfomance and load time is what you are looking for.

Øle Bjarnstroem at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

I think there will be no performance problem on data transfer since there are only 500 elements in the JSON file. But maybe you'll experiment performance problems in showing those 500 elements with AngularJS. Instead of pagination, you can checkout 'Infinite Scroll' with AngularJS, a good solution for result showing performance. Check this article: http://www.williambrownstreet.net/blog/2013/07/angularjs-my-solution-to-the-ng-repeat-performance-problem/ And no, I don't agree having a database in the middle. You are trying to use it as a cache, but you'll have more problems than solutions, because since you have only 500 elements, you would not gain performance at all. And another added problem: database maintenance ;) Cheers

jreyes

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.