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

Aleksandrs Karevs
PLUS
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,081 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