views:

92

answers:

2

Hello,

I am trying to use JSON to populate a div, so I basically run a loop to go through the entire data I get, about 200 records and fill it into a div.

It work great in most browsers, but IE it crawls to the core. Is there some solution to the problem?

Thank you for your time.

A: 

Last week I watched a Google Code talk about JavaScript optimization. There was a good discussion about looping, and I think I remember that $.each was slow. Not sure it'll help, but you may want to watch the video.

Nosredna
It would certainly be useful to build the same code using a for loop and see how significant the difference is.
Stuart Branham
+4  A: 

Are you adding each bit of data to the div at a time? Each addition makes the browser have to call a redraw, which you could save by concatenating and adding it all at the end.

function doStuff(json) {
    $.each(json,function(key, val) {
       $('#myEl').append(val); //redraws every time.
    });
}

function doStuffBetter(json) {
    var html = '';
    $.each(json,function(key, val) {
       html += val;
    });
    $('#myEl').append(html); //only 1 redraw
}
seanmonstar
its still slow :(
Alec Smart
And you still haven't shown us the code!
Nosredna
can you show us the code? or link to the site? We're stabbing in the dark here.
seanmonstar
found this question which might help solve your needs. doesn't decrease time, but doesn't lock the browser while doing so: http://stackoverflow.com/questions/788614/ways-to-increase-performance-when-set-big-value-to-innerhtml
seanmonstar