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

Development Tools Introduction to Front End Performance Optimization Combine and Minify Assets Minify Assets

Performance vs best pratice

The lecture suggests pasting small JavaScript or css into the html to speed up loading. However, this is contrary to best pratice to keep these concerns separate.

4 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Good question. :-)

I keep certain snippets of JavaScript code in my pages if I think it's appropriate. My CSS always goes in an external file. Just make sure your HTML remains organised. Put your code in certain "sections" separated by comments.

It's very difficult these days to write 100% valid code. :-)

I feel like it should be mentioned the lecture that putting the js or css in the html file is not best practice. I am not sure if saving a few milliseconds to make make future mantemance difficult is worth it.

Gavin Ralston
Gavin Ralston
28,770 Points

I think that depends entirely on your site.

Google, for instance, dumps it all on their page.

In the past, they used to leave closing tags off some elements which "required" it in order to save just a few precious bytes. Their current style guide includes the mantra "use valid css/html" but includes the caveat "where possible" because sometimes it simply...isn't.

Still, being forced to ignore some best practices in order to be ultra-optimized because you're one of the biggest services ever would be a dilemma anyone would love to have.

Seth Shober
Seth Shober
30,240 Points

It's best to learn and focus on best practices when starting out. You will find as you go along that everybody has their own opinion, and not every situation is the same. In a small site like in the example the javascript can be contained to the html because it is so small, it is not worth separating out. Generally separation of concerns will become evident as a project grows. The organization of code will become paramount and thus will be separated out. This is where coding can become an art.

You will develop a feel for this over time.

What is the best practice for applying CSS styles to your webpage (in regards to where the CSS should be located)? Thank you.