Javascript – Display large amount of data to client through pagination

asp.net-mvcjavascriptpagination

I have a web application in which i need to show a big number of data or records for clients. Now i 'll use pagination but i was wondering should I:

  1. Load all the data once then pagination, sorting and sarching 'll be easy..But it 'll takes big time(using local DB it takes up to 9 sec.)
  2. Or each time i show new page(from the pagination) i make a new request to server and then new request to DB to get the next records..But then what if the client click on Prev button, i 'll make a new request to get data that I had previously..Should i cach data that are loaded before and how if that's good technique?

So load all data once or make a new request every time i need data that maybe have been loaded before.

I'm using ASP.NET MVC SPA with durandaljs and knockoutjs

Best Answer

It's a tradeoff between speed, memory requirements in the cache, and programming required to keep the cache fresh. A lot depends on your use cases. For example

  • If, like Google search results, most users only ever read page 1, just a few carrying on down to page 2 and beyond, then cacheing may not even be necessary.

  • If users tend to repeatedly sort, search etc. then you can't cache individual pages because the number of combinations will overwhelm your storage. But if you have huge datasets, cacheing whole resultsets will do the same.

  • If the data in the background is liable to change a lot even during reading one page, and that is critical to the business, then the risk of displaying stale data may turn you against cacheing.

Personally, it might be a better investment of time to look at refactoring your db to squeeze more life out of it. If your queries are taking 9s it may be because the data model is too complex, you are missing important indexes, or you're keeping hold of old data in your main tables that should be archived away instead.

Related Topic