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 AJAX Basics AJAX Concepts A Simple AJAX Example

Dimitris Karatsoulas
Dimitris Karatsoulas
5,788 Points

Why do we have the script tag inside head?

We've been taught through previous courses that in general, we should avoid placing the <script> tag inside the head of HTML and instead place it inside body just above </body>. I notice that's not the case in this course. Is this an exception to the rule? Placing script inside body would make same or better results for us?

2 Answers

Steven Parker
Steven Parker
229,980 Points

The standard convention was a bit oversimplified originally. Scripts that only provide libraries and framework code that is not immediately invoked will typically be loaded in the head section.

Scripts that perform a function immediately will generally be located last in the body section, or they might be wrapped in an "onload" event handler, in which case they might also be placed in the head since they won't be invoked until the entire page has loaded.