How to tackle this problem?
tag to a HTML page is contextually equivalent to including files A and B altogether. By using this concatenated file we reduced the number of request to the server. However joining multiple files is a laborious task especially when it has to be done on every time the source is modified. For this reason, I wrote a small Java program to simply this task.
- Create a plain text file
- Enter the absolute path of all the source files you want to combine, one file per line (order matters)
- Run JsCombine.jar
java -jar JsCombine.jar fileListFileName outPutFileName
Let's say you have four js files under a folder (imageloader.js, loadingpanel.js, lib.js, functions.js) and you want to combine them into one file.
- Create a text file fileList.txt
- Edit fileList.txt
C:\Users\Cuong\Desktop\imageLoader\imageloader.js C:\Users\Cuong\Desktop\imageLoader\loadingpanel.js C:\Users\Cuong\Desktop\imageLoader\lib.js C:\Users\Cuong\Desktop\imageLoader\functions.js
- Run the following
java -jar JsCombine.jar fileList.txt one.js
Here's an example batch file in Windows:
java -jar JsCombine.jar C:\fileList.txt C:\one.js java -jar C:\yuicompressor-2.2.5.jar --type js C:\one.js -o C:\one-min.js