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

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.

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.

Thank you! That makes sense.

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!

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.