【发布时间】:2013-09-14 11:17:15
【问题描述】:
我在通过 ajax 加载的 json 文件中有大量数据行。
然后我创建了相当多的 html 代码,其中包含这样的每一行的一些数据。
var gl = $("#gameslist");
$.each(DATA.games, function(index, value) {
gl.append( '<div>... lots of html code here ... '+value.somedata+'</div>');
}
这似乎很慢,尤其是在移动 safari 浏览器上。是否有任何技巧或 jquery 插件可以加快速度?
编辑:根据要求,这里是 ajax 调用:
$.ajax({
dataType: "json",
url: "../games.json"
})
.done(function(gamesjson){
DATA = gamesjson;
buildPage(); // this one is calling the above code
})
.fail(function(){
console.log("games.json error");
})
;
【问题讨论】:
-
我不知道 jQuery 是怎么做到的,但是纯 Javascript 中的
insertAdjecentHTML可能会快得多。 -
不要使用.each 而是使用for循环?
-
你确定是这段代码很慢吗?你做了什么来查明问题?您能否向我们展示这段代码以及(可能)调用它的 AJAX 调用?
-
嘿,如果您能找到一些确凿的方法,那就太好了,那么您能否测试(使用计时器)并发布您所做的事情。
标签: javascript jquery html performance