Tuesday, July 10, 2012

[HTML] Where does JavaScript go on an HTML/PHP page?

The best place for Javascript code to go in a HTML or PHP document is at the end. See a discussion on WHY on StackOverflow. Basically, it boils down to the fact that when a browser renders JS, it is in a single-thread, causing the rest of the page to pause in rendering until the JS render is complete. By adding the JS at the end of the page, the content will load first and then the JS will render.


Post a Comment