What Happens At Render Time When This Occurs ?

Started by
0 comments, last by Matias Goldberg 8 years, 9 months ago

I was reading through some auto-generated JavaScript, when I noticed there were dozens of <script> tags all over the place - like this example


<html>
 <script> some code here </script><script> some code here </script><script> some code here </script><script> some code here </script>
</html>

.

At page render time, what actually happens ?

I am guessing that this example would open and close the JavaScript interpreter several times, slowing down the page rendering process.

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

Advertisement

Javascript interpreters are highly dependent on its implementation (what really happens depends on the browser). Some browsers may parse the whole page in one pass, others may parse it in multiple passes, some could be recursive.

However, without having looked at Chrome's or Firefox' code, it should be a good guess that this separation should be of little importance because Javascript is, by nature, JIT (the actual code needed cannot be compiled or interpreted until execution time due to lack of information in the code. e.g. 'var myVariable' could be holding a string, an integer, an array, or some weird object; and what they hold could change the next time the script is executed).

This topic is closed to new replies.

Advertisement