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 Object-Oriented JavaScript (2015) Prototypal Inheritance Building the Movie Object

kabir k
PLUS
kabir k
Courses Plus Student 18,036 Points

A single file for deployment

Andrew mentioned something to the effect that you should use one file when deploying your application so you don't end up making multiple requests.

How do you go about that and which file should you use?

3 Answers

Kevin Korte
Kevin Korte
28,149 Points

The easiest way I think is to use a javascript task runner like Grunt or Gulp. Either will do just fine. They use slightly different syntax to write your tasks, Grunt is more JSON like, while Gulp is more jQuery like. But both have a ton of plugins to help you do everything you would want to do.

The nice part is that you can break your java script up into as many files as makes sense to you. You can write and code in a developer friendly way. Than have Grunt or Gulp minify, and concatenate all of your javascript and files into one, super lean, no whitespace, unreadable file. Than serve that one file for maximum performance.

As far as file name, it doesn't matter...take your pick.

Kabir,

If I understand right, Andrew's just separating functionality into separate JS files for clarity, not convention. In the real world, you could simply combine all this code into a single JS file--no task runner setup (like Gulp, etc.) necessary.

Oly Su
Oly Su
6,119 Points

Hi there,

Just to add onto Kevin Korte's reply - my preference is using Gulp to concatenate all the JS files into one, and then minify with Uglify - this is the JS file that gets used in the production environment.

Treehouse recently introduced the Gulp course, and I highly recommend checking it out http://teamtreehouse.com/library/gulp-basics