A handy web tool to minify your JavaScript assets with the help of the fantastic UglifyJS library.
But anyway, let's not waste any time... get started by adding your files via the online form, or by reading about the API we've put together.
The API expects a HTTP POST request to the below API endpoint with content encoded using either application/x-www-form-urlencoded or multipart/form-data. The Content-Type header should be present and valid.
http://api.minifymyjs.net/v1/js
| Parameter | Description | Default |
|---|---|---|
| beautify | Passing a "1" prevents a lot of the white-space and surplus new lines from been removed (makes the final code more readable). | 0 |
| combine_statements | Joins multiple statements using the , operator. |
1 |
| exclude[] | Allows you to exclude certain variables/ function names from been mangled if either mangle or mangle_functions is set. This parameter can be provided multiple times e.g. exclude[]=foo&exclude[]=bar&exclude[]=baz |
n/a |
| file[] | Either a URI to a file which should be minified, or a block of code to be minified. This parameter must appear at least once in each request, but can be specified multiple times. Each request can mix & match different formats of the file[] parameter; e.g. file[]=http://example.com/application.js&file[]=function foo () { return false; } |
n/a |
| indent_level | Override the number of spaces used to indent code. Only valid with the beautify option. |
4 |
| indent_start | Initial indentation of the code. Only valid with the beautify option. |
0 |
| keep_copyright | To preserve the copyright notice (i.e. the first comment) that appears (in the first file only) pass a "1" here. | 0 |
| lift_variables | Prevent variable declarations from been hoisted to the top of the scope by passing a "0" here. | 1 |
| mangle | Whether to mangle variable names; this reduces the spaced used by code, but makes it harder to read. | 1 |
| mangle_functions | Whether to mangle function names; this reduces the spaced used by code, but makes it harder to read. | 1 |
| mangle_top_level | Whether to mangle the names of functions or variables that are accessible in the global scope. Enabling this option will break any external code that references your code. | 0 |
| max_line_length | Some older browsers/ proxies have been seen to choke on files which contain lines < ~32,000 characters. Pass a 0 here to disable the functionality. | 32,768 |
| quote_keys | If you'd prefer the keys of object literals to be always quoted, pass "1" as the value of this parameter. Keys that must be quoted (e.g. those that equal reserved words will always be quoted regardless of this setting). | 0 |
| remove_dead_code | By default, code which is proven to be unreachable is removed from the output. Pass a "0" here to disable this functionality. | 1 |
| response | Specifies the type of response you wish to receive. For more information on the different response types, please see below. | http |
| space_colon | Forces a space to appear between the object key and the ":" in object literal notation. Only valid with the beautify option. |
0 |
| unsafe | Makes transformations that could be unsafe in some situations. Use of the Array constructor is replaced with literal notation (new Array(1,2,3) becomes [1,2,3]) and use of obj.toString() is replaced with +obj. Enabling this option will only break the semantics of your code if you've overridden the Array function or are using toString() in weird and wonderful ways. |
0 |
The API can respond in a variety of different formats; with the default been http. The response format can be specified using the response parameter documented above.
| Format | Description |
|---|---|
| http | A successful response provides a HTTP status code of 200: OK. In this circumstance the response body contains the minified source code. An unsuccessful request returns a 406: Not Acceptable status code, and the response body contains a brief description on the failure. |
| json | The API always returns a HTTP status code of 200: OK. The JSON formatted string returned contains a success attribute whose value is a boolean indicating whether the response was succesful. A successful request will have an output property which contains the minified code, whilst an unsuccessful request will have an error property containing a brief description on the failure {
"status": true,
"output": "/* your minified code */"
}{
"status": false,
"error": "file[] must be specified at least once. Please check the documentation."
}
|
Mangling your code will rename all variables and functions to much shorter (but less readable) alternatives.
If you choose to format your code, most of the white-space and new lines will be preserved (as opposed to being removed).
Array constructor to literal notation ([1,2,3]). Converts obj.toString() to obj+''. These optimizations should be safe in most environments.