简体   繁体   English

如何使大数据(在HTTP或WebPage上)的JSON加载速度更快

[英]How to make JSON loads faster with large data (on HTTP or WebPage)

. Requesting the page(on HTTP or WebPage), it is very slow or even crash unless i load my JSON with fewer data. 请求页面(在HTTP或WebPage上),除非我用更少的数据加载JSON,否则它非常缓慢甚至崩溃。 I really need to solve this since sooner or later i will be using large amount of data frequently. 我确实需要解决此问题,因为迟早我会经常使用大量数据。 Here are my JSON data. 这是我的JSON数据。 --->>> --- >>> 单击此处以JSON树视图

Notes: 1. The JSON loads only String and Integer. 注意:1. JSON仅加载String和Integer。 2. I used to view my JSON in JSONView more like treeview using plugin from GoogleChrome. 2.我以前使用GoogleChrome的插件在JSONView中查看JSON,更像treeview。

I am using angular and nodejs. 我正在使用angular和nodejs。 tq TQ

A quick resume of all the things that comes to my mind : 快速介绍一下我想到的所有事情:

I had a similar issue once. 我曾经有过类似的问题。 My solutions may make the UI change. 我的解决方案可能会更改UI。

  1. Pagination 分页

I doubt you can display that much data at one time, so the strategy should be divising your data in small amounts and then only load more when the client ask for it. 我怀疑您一次可以显示那么多数据,因此该策略应该将您的数据分成少量,然后仅在客户要求时才加载更多数据。

This way, the whole data is no longer stored in RAM as it is currently. 这样,整个数据不再像当前那样存储在RAM中。 This is how forums works (only 20 topics at a time). 论坛就是这样工作的(一次仅20个主题)。

Just imagine if StackOverflow make you load the whole historic of questions in the main page, how much GB would your navigator need just for that ? 试想一下,如果StackOverflow使您可以在首页中加载问题的整个历史记录,那么导航器仅需要多少GB?

You can use pagination in a classic way (button with page number, like google), or in an infinite scroll way, as you want. 您可以根据需要以经典方式(带有页码的按钮,例如google)使用分页,也可以无限滚动方式使用分页。

For that you need to adapt your api and keep track of the index of the pages you already loaded at every moment in your Front. 为此,您需要调整api并跟踪Front中每时每刻已经加载的页面的索引。 There are plenty of examples in AngularJS. AngularJS中有很多示例。

  1. Only show the beginning of the data 只显示数据的开头

When you look at Facebook comments, you may have a "show more" button. 当您查看Facebook评论时,您可能会有一个“显示更多”按钮。 In their case, maybe it's to not break the UI, but it can also be used to not overload data. 在他们的情况下,也许是为了不破坏UI,但也可以用来不使数据过载。

You can display only the main lines of your datae (titles or somewhat) and add a button so the user can load more details if they want. 您只能显示数据的主行(标题或某些行)并添加按钮,以便用户可以根据需要加载更多详细信息。

In your data model, the cost seems to be on the second level of "C". 在您的数据模型中,成本似乎在“ C”的第二级。 Just load data untill this second level, and download the remaining part ( for this object ) only if the user asks for. 只需加载数据直到第二级,然后仅在用户要求时下载其余部分( 针对此对象 )即可。

Once again, no need to overload, your client's RAM will be thankfull, and your client's mobile 3G too. 再一次,不必超载,您的客户端的RAM将非常感谢,并且您的客户端的移动3G也将如此。

  1. Optimize your data stucture 优化数据结构

If this is still not enough : 如果还不够:

  • As StefanArya said in comment, indeed remove the "I" attribute, which is redundant with the JSON key. 正如StefanArya在评论中所说,的确删除了“ I”属性,该属性与JSON密钥无关

Remove the "I" as you can use Object.keys() to get key name. 删除“ I”,因为您可以使用Object.keys()获得密钥名称。

  • You also may don't need that much precision on your floats. 您可能也不需要浮标那么多的精度。

If I see any other ideas, I'll edit this post later. 如果有其他想法,我将在以后编辑此帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM