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 AJAX Basics (retiring) jQuery and AJAX Posting Data with jQuery

Aleksandrs Karevs
Aleksandrs Karevs
Courses Plus Student 11,178 Points

Isn't it a bad practice to insert scripts directly into the HTML?

I've read in Jon Duckett's book – "Javascript & jQuery – interactive front-end development" that it is generally considered a bad practice to insert your scripts directly into the HTML document. Instead, you are better of inserting it into a separate .js file and than linking back to it from within HTML.

What are your thoughts on this subject?

4 Answers

Josselin Cuette
Josselin Cuette
2,672 Points

You are right, it is bad practice, but I think that this kind of course intends to simplify things for the sake of demonstration. :)

Great course! But I agree, best practices should be taught alongside the course content. Newer programmers may assume this is ok when it isn't.

Jeremy Castanza
Jeremy Castanza
12,080 Points

Good observation. Typically, there's a pattern to follow and best practices dictate separating structure, design, and behavior in a web page.

  • HTML Files - Used for structure
  • CSS Files - Used for design/layout
  • Javascript Files - Used for behavior/manipulation