I'm currently making a college project in which at some point i need to load large ammounts os HTML into a div. I'm doing this like so
$('#output-div').html(codHTML);
Note that the variable "codHTML" is the variable that contains the large ammounts of HTML
The contents of the HTML code aren't much more then <span>
, <b>
and <p>
and text that is retrieved by a JSON search.
This is where i fill the codHTML variable
for(iTest=0; iTest<nTests; iTest++){
nLivros=numLivrosTest(iTest);
for(iLivro=0; iLivro<nLivros; iLivro++){
nCaps=numCapsLivroTest(iTest, iLivro);
for(iCap=0; iCap<nCaps; iCap++){
nVerss=numVerssCapLivroTest(iTest, iLivro, iCap);
for(iVers=0; iVers<nVerss; iVers++){
txtVers = txtVersCapLivroTest(iTest, iLivro, iCap, iVers);
regexArray = txtVers.match(regex);
if(regexArray!= null){
txtVersFinal = delimit(txtVersCapLivroTest(iTest, iLivro, iCap, iVers), regex, regexArray);
codHTML += '<p>' + refVers(iTest, iLivro, iCap, iVers) + txtVersFinal+ '</p>';
}
}
}
}
}
The delimit function, what it does is add bold elements to specified words. In the example bellow it's the "the" word
Functions started by "num" are related to the JSON search, they return the total number of childNodes of a certain parentNod.
The function refVers returns a String built with the names of parentNodes
Here's an example of how it looks:
My problem is that whenever the time comes that i load the html to the div, the page freezes for an extended period of time. I've investigate this and i can tell that the problem is NOT on the JSON search NOR it is when i inject the variable contents inside the div itself. The problem remains on the time the browsers take to actually display the results of that injection.
So after extensive research i am sad to say that i have found zero solutions to reduce the page freeze time.
If anyone knows how i can get around this delay, i would really apreciate if you told me.
Thank you in advance.