I am generating a lot of content on a page via javascript and I am noticing that the page won't display anything at all until the javascript has finished running. If you run this simple page, you can see the numbers counting down in the console and then when the loop is done, finally the content loads on the page.
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
Hello
<script>
$(function(){
for(var i=9999; i>0; i--){
console.log(i)
$('body').append('<p>' + i*i*i + '987987 Lorem ipsum dolor sit amet. </p>')
}
})
</script>
</body>
</html>
Isn't there a way to a) display the static page content immediately and b) display each bit of generated text as soon as it is created? Am I right to guess that if there is a way it will slow down the loop a lot? Maybe I could have a compromise where it displays a screen-worth of content immediately and then loops quickly through the rest in the usual manner. I just don't want to have to sit for a few seconds to wait to see the content on the page when I know it has already been generated.