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
Aaron Walton
3,557 PointsJavascript in the head tag?
I'm using javascript to initialize Google Maps on a page. Since this JS is only used on one page I'd prefer not to have it in the head tags that are common to all site pages. I put the javascript in the body of the page and it seems to run fine. So the question is: will this be a problem? Is there a reason the JS should go in the head tag?
I realize I can use PHP to create a conditional to display the JS in the head tag only on selected pages but I'd still prefer to not have it there and keep the head as clean as possible.
1 Answer
Scott Magdalein
2,406 PointsNo, this is fine. Placing JS in the <head> should cause it to load before the rest of the page. But putting your JS call in a script tag inside the body is acceptable for your scenario.