"Python Basics (2015)" was retired on June 22, 2018. You are now viewing the recommended replacement.

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

I have several pieces of Javascript and Jquery scripts in my index.html file, how do I merge them together?

Hello, how about I got to create a maybe a main.js file with bit pieces of codes that make different functions?

I have got something like this, looks kinda messy in my HTML, making my head too large

 <!-- Aditional scripts -->
        <script src="js/slidenavbar.js"></script>
        <script src="js/blurnavbar.js"></script>
        <script src="js/sidebar.js"></script>
        <script src="js/hashes.js"></script>
         <script type="text/javascript" src="js/smooth-scroll.min.js"></script>
        <script type="text/javascript" src="js/smooth-scroll-config.js"></script>
         <script src="js/initpopup.js"></script>

          ```

1 Answer

I would simply copy and paste all my pages of code into one document called main.js. However, there are some free sites that allow you to upload a folder of javascript code and compress them into a single file.

Here are some examples:

  1. https://jscompress.com/
  2. https://www.filesmerge.com/merge-javascript-files
  3. http://www.shrinker.ch/

The reason you want to do this is not only because your head will fill up, but also your site will load faster in browsers.

I would compile a script for bootstrap and a seperate script for jquery.

Thank you! Hopefully all will still work. What about external scripts for example boostrap and jquery?