menardmam menardmam - 13 days ago 6
PHP Question

Choking browser on html output

I have a BIG table to output to HTML and into the browser. When the table is 200 lines, it's fine, but when it 20,000 lines, it chokes the browser. I output everything into a variable with

$html .= '<td> and <th>'
and then at the end,
echo $html
. On my new Mac, with SSD and 32 gig ram, a 20,000 line table takes about 6 seconds to load, but stops everything. the colorful ball of death spins, the music stops playing, and then the thing appears, and everything continues as normal.

The question is: how do I output a large table in the browser without making it choke?

Note, just as Freddy Mercury said, I want it all, and I want it now. So, please don't tell me to make a paging table of 20 rows at the time. I know how to do that, and I don't want to do it. Anyway, to make it, you have to load ALL THE ROWS, and show only 20, which causes the same choking!

Answer

Anyway, to make it, you have to load ALL THE ROWS, and show only 20, which causes the same choking!

That's definitely a bad idea. I would write a method in your model that gets the next n number of records. You can call this method via Ajax on initial page load, and then again each time the user clicks a "Next N Entries" link and update the page.

You definitely don't want to load the HTML for 20K items and use jQuery to hide and show n records at a time; the DOM traversal will take FOREVER in the good browsers and will completely crash IE.

Comments