You know what, I have to agree here that only calculating it when needed is a better idea. Thinking of it, the call do docElement.scrollHeight just might be causing a reflow, which can easily be avoided. I am going to update the function accordingly.