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

Sergi Beltran
Sergi Beltran
18,493 Points

How to organize your custom javascript files?

Hi everyone, I have a Wordpress project using Bootstrap 3 as a FrontEnd framework.

I realised that if you want to call just some of Bootstrap's javascript libraries they use for example: "//= require ./bootstrap/modal".

Right now all my custom javascript are in single javascript file, a complete disorder and I would like organize my files separately and add all of these into one single javascript file.

What is best way to do that?

2 Answers

Sergi Beltran
Sergi Beltran
18,493 Points

I've found a good way to compile all my assets with Grunt.js.

Furthermore I also I've found a tutorial to implement the compilations and compress all the javascript and sass.

Instead of adding all the files to a Javascript file, you can include them sequentially into your <head> of your HTML file. That's the way I've seen it done, at least. Code from <scripts> will be included in any below <scripts>

Sergi Beltran
Sergi Beltran
18,493 Points

This way is not best solution because you are calling to many times to server to download your scripts.

The better way is encapsulate all you need as least callings you could.