I am using jquery in my web application and I need to load more jquery script files into a single page.
Google suggested I combine all the jquery script files into a single file.
How can I do this?
$ ./compressJS.sh some-script.js another-sctipt.js onemore.js
Just combine the text files and then use something like the YUI Compressor.
Files can be easily combined using the command
cat *.js > main.js and main.js can then be run through the YUI compressor using
java -jar yuicompressor-x.y.z.jar -o main.min.js main.js.
Update Aug 2014
Try the google closure compiler:
You can do this via
- b. Use PHP: Just create an array of all JS files and
includethem all and output into a
I usually have it on a
# All .js compiled into a single one. compiled=./path/of/js/main.js compile: @find ./path/of/js -type f -name "*.js" | xargs cat > $(compiled)
Then you run:
I hope it helps.
I use this shell script on Linux https://github.com/eloone/mergejs.
Compared to the above scripts it has the advantages of being very simple to use, and a big plus is that you can list the js files you want to merge in an input text file and not in the command line, so your list is reusable and you don’t have to type it every time you want to merge your files. It’s very handy since you will repeat this step every time you want to push into production. You can also comment files you don’t want to merge in the list. The command line you would most likely type is :
$ mergejs js_files_list.txt output.js
And if you want to also compress the resulting merged file :
$ mergejs -c js_files_list.txt output.js
This will create
output-min.js minified by Google’s closure compiler. Or :
$ mergejs -c js_files_list.txt output.js output.minified.js
If you want a specific name for your minified file named
I find it really helpful for a simple website.