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 AngularJS Basics (1.x) Getting Started with Angular Setting Up Your First Angular App

Tzili Hod
Tzili Hod
5,836 Points

Why is angular included in body tag?

Why is Angular included in the body tag as opposed to the head tag? Same for app.js.

3 Answers

It is best practice to put your script loads right before the closing body tag of your html. You should let you html structure load before trying to load in any JS files which could be long and take time to load. That way your user won't be stuck looking at a blank page while you JS files are loading. Here is a more in depth explanation https://teamtreehouse.com/community/best-practice-where-to-include-your-script-tags Let me know if you have any other questions.

Mister Moody
Mister Moody
41,727 Points

With standard JavaScript, I would def follow your advice. Just not so sure about this question as I am certain that the instructor intentionally placed the JS Script in the <head> Tag, for whatever(?) purpose.

Tzili Hod
Tzili Hod
5,836 Points

Thank you! That makes sense.

Kevin McNamara
Kevin McNamara
7,483 Points

Related question: what does the vendor/angular.js script even do? I don't quite understand where that code is coming from, or what its purpose is. Thanks!

Farid Wilhelm Zimmermann
Farid Wilhelm Zimmermann
16,741 Points

The vendor/angular.js is the file, which basically holds the "angular framework".

We have many different ways of including frameworks and libraries in our code, we can either use a CDN(Content Delivery Network, think about Bootstrap or jQuery etc.), but we can also just download the framework file and include it in our code manually (like if we'd run our own webserver, that way we would have more control over the version we use, would help us customizing etc.).

We have to link it before our app.js file, so that we can access angular functions/methods inside our app.js file.