2019
(Probably the correct answer is correct for 2010). Here's an answer for 2019 with benchmark.
Generating table with nested div
, total of 500 rows, 250k table cells, 10 nested divs per table cell.
<!-- Pure HTML by server -->
<html>
<head></head>
<body>
<table>
<?php
for($i = 0; $i < 500; ++$i) {
echo '<tr>';
for($j = 0; $j < 500; ++$j) {
echo '<td><div><div><div><div><div><div><div><div><div><div>' . $i . '/' . $j . '</div></div></div></div></div></div></div></div></div></div></td>';
}
echo '</tr>';
}
?>
</table>
<script>
alert('finish');
</script>
</body>
</html>
And the below HTML generated by JS:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
var html = '<table>';
for(var i = 0; i < 500; ++i) {
html += '<tr>';
for(var j = 0; j < 500; ++j) {
html += '<td><div><div><div><div><div><div><div><div><div><div>' + i + '/' + j + '</div></div></div></div></div></div></div></div></div></div></td>';
}
html += '</tr>';
}
html += '</table>';
$('body').html(html);
alert('finish');
});
</script>
</body>
</html>
Approx. Result:
| Download Size | Time 'til browser stops loading
--------------------------------------------------------------------------
HTML generated by server | 680,000 bytes | 00:01:48
HTML generated by JS | 570 bytes | 00:00:28
Tested it on Chrome v70 on Ubuntu 18. HTML generated by JS is approximately 400% faster in this test case (speed & download size will depend on how big is the HTML of course in your real case).
Conclusion
Always stick to normal HTML for many reasons (usually for readable/maintainable code), unless you're dealing with huge HTML then you may consider generating it by JS.