Combining JavaScript manually is effective, but it is quite a tedious task. So, here is a great way to make this a little easier.
As an example, if you have a JavaScript file called main.js
, you can include other JavaScript file contents in the main file by using an include statement. Here is an example:
#include file="js/jquery.js"
If file concatenation has been enabled on the server, the contents of jquery.js
will be inserted into the main.js
file.
You can make use of a tool available from http://yui.github.io/yuicompressor/ for this. There is also Grunt or Gulp that you can use to automate both file concatenation and CSS minifying. Both of these are task runners. They allow you to automate your web development. Both are very well-supported and have plenty of documentation as well.