简体   繁体   English

以json或html文件加载数据是否更快?

[英]Is it faster to load data as json or from a html file?

The title phrases it badly so here's a longer description : 标题短语很糟糕,所以这里有一个更长的描述:

I have an application that exports data in html format. 我有一个以html格式导出数据的应用程序。 ( 500 rows, 20 columns) It looks terrible with lots of useless columns. (500行,20列)很多无用的列看起来很糟糕。

I want to use something like datatables to make a more usable table, ie paging/sorting/filtering/hiding columns 我想使用像datatables这样的东西来制作一个更有用的表,即分页/排序/过滤/隐藏列

The option I'm trying first is to insert the table from the exported html file using the .load() function from jquery. 我首先尝试的选项是使用jquery中的.load()函数从导出的html文件中插入表。 Then I loop through the table deleting/modifying columns. 然后我循环删除/修改列表。

This seems very slow (I suspect my looping and searching) so I'm looking for improvements. 这似乎很慢(我怀疑我的循环和搜索)所以我正在寻找改进。

One idea is to pre-convert my exported html file to json (using notepad++ macros or something like that) and then build the table that I want from that json file. 一个想法是将我导出的html文件预转换为json(使用notepad ++宏或类似的东西),然后从该json文件构建我想要的表。

Any opinions on whether I can expect a large performace boost, or potential problems to look out for ? 关于我是否可以期待大幅度提升或潜在问题需要注意的任何意见?

Many thanks / Colm 非常感谢/ Colm

JSON should be faster, when its loaded its ready to go without all of the text parsing you would need to do with a text file. JSON应该更快,当它加载它准备好时,没有你需要用文本文件进行的所有文本解析。 Lots of other jquery addons available to make it easy for you once it is in JSON. 许多其他jquery插件可以让你在使用JSON时轻松实现。

I think this is not about which loads data faster but which solution is better for your problem. 我认为这不是关于哪种加载数据更快,而是哪种解决方案更适合您的问题。 Datatables is very flexible and you can load from different sources. 数据表非常灵活,您可以从不同的来源加载。 Take a look at the "Data Sources" and "Server side processing" in the examples: http://datatables.net/examples/ 请查看示例中的“数据源”和“服务器端处理”: http//datatables.net/examples/

Datatables uses mostly JSON format. Datatables主要使用JSON格式。 To process your data need to find the best approach; 处理您的数据需要找到最佳方法; convert your exported html file, process the file with javascript to convert data (jquery can help you here), etc.. 转换导出的html文件,用javascript处理文件转换数据(jquery可以帮到你),等等。

This page gives some real world examples of loading data in json vs data in a html table. 这个页面提供了一些真实世界的例子,用于在json表中加载json与数据。 Fairly conclusive, see the post from sd_zuo on July 2010, a fourfold increase in speed loading from json and then just building the table that you want to display. 相当确定,请参阅2010年7月的sd_zuo帖子,json的速度加载速度增加了四倍,然后只需构建要显示的表格。

Granted the page deals specifically with the slowness of the innerHtml function in IE8 but I think I'll give it a go in json and see how it compares across a couple of browsers. 该页面专门讨论了IE8中innerHtml函数的缓慢性,但我想我会在json中给它一个去看看它是如何在几个浏览器中进行比较的。

PS This page gives good advice on fast creation of html using raw javascript and then only using jquery to insert one full row at a time PS 这个页面提供了很好的建议,使用原始javascript快速创建html,然后只使用jquery一次插入一整行

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

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