There are some really excellent command line tools for this, but you can also easily do this with a text editor. The easiest way is to simply open each file, copy the contents and paste the contents into one JS file (for example, "all-all-together.js"). You need to make sure that you insert the files into one file in the same order in which you placed the script tags in the HTML document. After all the files are merged, you can use tools such as JSXMin, YUI Compressor or Google Closure. There are also some online tools that do this, such as http://www.minifyjavascript.com/ . You can paste uncompressed JS and copy back compressed JS. This makes the build process really cumbersome, but if you just need to do it once, it will take you there.
The best way to do this is to do it as a build step for the site. This means that when you make changes to the JS files, you rebuild the compressed JS file to include the changes. This can be a cumbersome step if you repeat and change files over and over again. You do not want to recompile the compressed file each time you save. You can solve this problem by setting up ways to design and produce a site. When loading in development mode, JS files are not grouped. When all the necessary changes are made, you will restart the build step to create a single compressed JS file. To perform minimization from the command line, you probably want to use Google Closure: https://developers.google.com/closure/compiler/ . If you download the compiler application, you can do the following:
java -jar compiler.jar some-file.js some-other-file.js> compiled.js
This will create a file called compiled.js that will contain the contents of some-file.js and some-other-file.js in a mini format. You can specify as many files to compile as you need. In fact, I am selling Closure a little shorter to say that it is just mined. It is also extremely optimized code. Almost every site should do this with all JSs all the time, if they don’t already do something better.
Jackson gabbard
source share