Javascript 响应浏览器的最大 json 大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8937516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 08:08:51  来源:igfitidea点击:

Maximum json size for response to the browser

javascriptjquerytree

提问by ankur

I am creating tree with some custom control prepared with JavaScript/jquery.

我正在使用一些用 JavaScript/jquery 准备的自定义控件创建树。

For creating the tree we are supplying json object as the input to java-script to iterate through and create the tree.

为了创建树,我们提供 json 对象作为 java-script 的输入,以迭代并创建树。

Since the volume of data may go up-to 25K nodes. during a basic load test we identified that the browser will be crashed for such volume.

由于数据量可能高达 25K 个节点。在基本负载测试期间,我们发现浏览器会因为这样的音量而崩溃。

The alternate solution is just load first level of the nodes and rest load on demand via AJAX request. the volume of first level can vary up-to 500 - 1K nodes.

替代解决方案只是加载第一级节点并通过 AJAX 请求按需加载。第一级的数量最多可以有 500 - 1K 个节点。

What is the max size a json should have as a response from the server. What could be the best approach to process such volume of data on browser.

作为来自服务器的响应,json 应该具有的最大大小是多少。在浏览器上处理如此大量数据的最佳方法是什么。

采纳答案by xdazz

There is no max size limit of the http response (or the max size of Int or the limit of browser or the limit of server have been configured).

http 响应没有最大大小限制(或者已经配置了 Int 的最大大小或浏览器的限制或服务器的限制)。

The best approach is use AJAX to load part of data while it need to be shown.

最好的方法是使用 AJAX 加载需要显示的部分数据。

回答by Shiplu Mokaddim

An HTTP response has no size limit. JSON is coming as an HTTP response. So it has no size limit either.

HTTP 响应没有大小限制。JSON 将作为 HTTP 响应出现。所以它也没有大小限制。

There might be problem if the object parsed from JSON response consumes too much memory. It'll crash the browser. So it's better you test with different data sizes and check whether your app works correctly.

如果从 JSON 响应解析的对象消耗太多内存,则可能会出现问题。它会使浏览器崩溃。因此,最好使用不同的数据大小进行测试并检查您的应用程序是否正常工作。

I think lazy-loadingis the best approach for such large amounts of data. Especially when dealing with object literals.

我认为延迟加载是处理如此大量数据的最佳方法。特别是在处理对象文字时。

See High Performance Ajax Applicationpresentation from Yahoo.

请参阅来自 Yahoo 的高性能 Ajax 应用程序演示。

回答by Bunti

Well I think I am too late to give my two cents. Complementing shiplu.mokadd.im's answer browser memory is a limitation and HTTP response can have any amount of data according to the TCP spec.

好吧,我想我给我的两分钱太晚了。补充shiplu.mokadd.im的答案浏览器内存是一个限制,根据 TCP 规范,HTTP 响应可以包含任意数量的数据。

But I have an application that uses Google Chrome (version 29.0.xx) and Jetty server where response from the Jetty server has a payload amounting to 335MB. While the browser is receiving the response of that sheer size Chrome stops leaving the message "IPC message is too big". Though this is specific to Google Chrome(not sure about other browsers), there should be a threshold on the max size of response.

但是我有一个使用 Google Chrome(版本 29.0.xx)和 Jetty 服务器的应用程序,其中来自 Jetty 服务器的响应的有效负载为 335MB。当浏览器收到如此庞大尺寸的响应时,Chrome 停止留下消息“IPC 消息太大”。尽管这是针对 Google Chrome 的(不确定其他浏览器),但响应的最大大小应该有一个阈值。