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

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.