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 Foundations Strings Basics

Dylan Marsh
Dylan Marsh
4,328 Points

Calling your script tags - Best practice?

So I noticed that you call your Script tags at the bottom of the document body. I also know it's common to call them in the head and add a handler in your code for when the page loads (AKA $(document).ready for jQuery or .onLoad ). What are the pros and cons for each method? Which one would you consider to be BEST practice?

1 Answer

Steven Byington
Steven Byington
13,584 Points

A lot of it comes from personal opinion, but I would say the general consensus is that it is best to put at the bottom of the body. The exception is if it a script that should run before the page loads(IE. Modenizr). If you test out your site at google's page insights they will also advise you to place script files at the bottom of the body.