Javascript minifiers
JavaScript minification reduces your JavaScript file size obviously without changing its functionality. Here let’s see several JavaScript minification tools including one command tool and two online ones.
JS minify command tool: JSMin
JSMin is an open-source minification tool that you can download to your local machine and use it as a command line. It allows pass optional parameters so it is convenient to add a copyright message at the beginning.
$ jsmin <fulljslint.js >jslint.js "(c)2002 Douglas Crockford"
It removes comments and unnecessary whitespace and typically reduces filesize by half. It replaces carriage returns ('\r'
) with linefeeds ('\n'
).
JS minify online tool: JSCompress (supports uploading multiple files)
JSCompress says it can compress and minify all of your JS files by up to 80% of their original size. You can paste your code or you can upload JavaScript files (Yes, you can upload multiple files and compress to one) then copy or download the output.
It uses UglifyJS 3 and babel-minify for all JavaScript minification and compression.
JS minify online tool: JavaScript Minifier (provides an API)
JavaScript Minifier does not provide uploading and downloading, to use it you just paste code as input and copy the output.
It provides an API that you can use to perform minification in a programming way with many languages. You just need to make a POST request to https://javascript-minifier.com/raw
with the input
parameter set to the JavaScript you want to minify. Below are examples using wget
and curl
commands to make the request.
# Use wget
$ wget --post-data="input=`cat main.js`" --output-document=main.min.js https://javascript-minifier.com/raw
# Use curl
$ curl -X POST -s --data-urlencode 'input@main.js' https://javascript-minifier.com/raw > main.min.js
JS minify online tool: Minifier JS Online (offers minification options)
Minifier JS Online does not provide uploading and downloading either.But it offers some options before minifying:
Preserve compatibility with IE6-8
Display output indented
Change names of local variables
Reserve words (You can input some words that can be reserved)
It is based on UglifyJS2 project by Mihai Bazon. The input size is limited to 2 MB.