Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Introducing JavaScript Review Adding Scripts and Simple JavaScript Commands

Joe Beard
Joe Beard
492 Points

I've reached this question about putting in JavaScript before the closing </body> tag. What is the answer?

Is it that one about the visitors being able to see the code before it runs? Could you tell me why the right answer is right?

4 Answers

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,349 Points

When a webpage loads, it renders the html code in the browser and styles the html code with css. This is the part of the page you see. You can not see JavaScript, but it will run in the background adding functionality to the page. It takes some amount of time for the browser load the html, css, and JavaScript. Therefore we want to load the html and css first, so we can see the page. Then the JavaScript loads in the background while we don't notice it. If you load the JavaScript first, which you can do if you choose to, it might cause a delay for the user from being able to view the page. It would be an annoying user experience and poor web site performance.

Erik Robles
PLUS
Erik Robles
Courses Plus Student 10,635 Points

Of course this is becoming less and less of an issue as there has been more of an effort to standardize. There are also ways in Javascript to handle this as well.

Joe Beard
Joe Beard
492 Points

Your answers were both very helpful. Thanks so much!

The users can view the contents of a webpage before JavaScript starts