JavaScript Source Compressor 1.00.A
JavaScript Source Compressor is a perl script that can be used to compress the Javascript source file to a much smaller file. The script will replaces large variable names with smaller, generic names and removes unwanted white spaces. By default it will take compress the javascirpt source code given as the arguments and save it as a different file. For example, if the given Javascript code is in the fle 'js_file.js', the script will compress the file and save it to a different file called 'js_file_compressed.js'. Use the second file as the Script file in the HTML page like...
<script language="Javascript" src="js_file_compressed.js" type="text/javascript"></script>
Download the code for JavaScript Source Compressor. The script is distributed in GPL license - so feel free to modify it. NOTE : You should have Perl on your system to use this script.
Features- Removes Comments - both
//...
and/* ... */
style comments. - Removes White spaces - newlines, spaces and tabs.
- Replaces all variable names with a shorter version(a,b,...,z,aa,ab,...).
SourceCompressor is a perl script that can be used to compress the Javascript source file to a much smaller file. Replaces large variable names with smaller, generic names and removes unwanted white spaces.
Usageperl compressor.pl <JS File> [options]
Example :
perl compressor.pl settings.js -display -verbose -change-name
Command Line Options
The first argument MUST be the file name of the JavaScript file.
-verbose - Show details of what is going on.
-readable - Use \\n instead of ';' as the command separator.
-change-name - Rename the variables to a shorter version. Enabled by default.
-remove-vars - Remove the 'var' keyword - this is asking for trouble.
-print - Outputs the compressed data instead of writing it to a file.
- BUG: Changes the text if the variable name appears in the comments/strings/other places.
- The variables appearing more times must have shorter number of chars.
- Change the variables that don't use the 'var' declaration method. - Is this possible?
- Implement Un-removeable comments - needed for copyright statements.
- Change the names of the functions/classes too?