解析大数据哪个更好
我有一个 PHP 数据数组。它是大量特定格式的数据。它的形式是树
。即数组包含 n 维。我需要通过将数据与内联编辑
功能和ajax保存绑定来将数据解析为可编辑的html格式。
将其视为一个非常巨大的形式。
从服务器获取数据时哪种方法更好?
将此数据编码为 JSON,减小传输大小并使用 Javascript 使用 DFS(深度优先搜索)函数解析它。
使用PHP在服务器端使用DFS解析数据,并在客户端获取形成的DOM。
在第一种方法中,数据足够小,即使在较慢的连接中也可以传输,但是会有大量的回流访问 DOM 多次。
在第二种方法中,数据是第一种方法中的两倍多...(即添加所有标签和属性)。但 DOM 在客户端完全不受干扰。
JSON 将包含许多短数据,这使得它很大。它不包含段落。它包含短字符串和布尔数据,但采用树数据结构。
我可以牺牲哪一个? DOM 或传输量。有没有更好的转运方法?还是我有什么地方说错了?
I'm having an array of data in PHP. It is a lot of data of a particular format. It is of the form of a tree
. That is the array contains n dimensions. I need to parse the data into editable html format by binding the data with inline editing
feature with ajax save.
Think it of as a very huge form.
While getting the data from the server which method is better?
Encoding this data into JSON, make the transfer size small and parse it using a DFS(Depth First Search) function using Javascript.
Parse the data using DFS on the server side using PHP, and get the formed DOM at the client side.
In the first method, the data is small enough to be transferred even in a slow connection, but there will be lots and lots of reflow accessing the DOM that many number of times.
In the second method, the data is more than twice as large as it was in the first method... (i.e. adding all the tags and attributes). But the DOM is not disturbed at all in the client side.
The JSON would consist of many short data, that makes it large. It doesnt contain paragraphs. It contains short strings and boolean data, but in a tree data structure.
Which can I sacrifice? DOM or the amount of transfer. Is there any better method of transfer ? Or am I wrong at some place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理论上,当启用 gzip 压缩时,JSON 和形成的 DOM 之间的大小应该没有太大差异。
In theory there should be no much difference in size between JSON and formed DOM when gzip compression is on.