Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Introduction to jQuery Ways to Include jQuery in a Project

Sanjeev Veloo
Sanjeev Veloo
4,713 Points

When using Ajax, does jQuery need to be in the header?

You know everyone's saying to place the jquery scripts in the footer, but what about when you are using Ajax? Is this the exeption when you need the jquery stuff to be in the header of your page?

2 Answers

.a{fill-rule:evenodd;}techdegree seal-36
Front End Web Development Techdegree Graduate 56,488 Points

No, you should still use it after your content.

The reason for this is that you allow your content to load before the ajax request, preventing a situation where the user has to wait for a JavaScript file to load before getting to see any content.

Christopher Debove
Christopher Debove
Courses Plus Student 18,372 Points


Like Stjarnan said, all your scripts should be at the end of your HTML for better performance. Then your scripts which using jQuery (and potentially Ajax) should be added after the jQuery script.