FCKeditor - FCKpackager - JavaScript Compressor Tool

FCKeditor

This HTML text editor brings to the web much of the power of desktop editors like MS Word. It's lightweight and doesn't require any kind of installation on the client computer.
  
Current Release
2.6.4

FCKpackager - JavaScript Compressor Tool

FCKpackager is a simple command line application which compacts and optimizes one or many JavaScript source files on fewer and smaller files.

Download

FCKpackager is currently available at our SVN only. To download it, just follow this link:
http://svn.fckeditor.net/FCKpackager/trunk/fckpackager.exe

The PHP version of it is also available for download here:
http://svn.fckeditor.net/FCKpackager/trunk/fckpackager.php

To execute the PHP version, just run it in the command line with PHP:

php fckpackager.php

Features: Simple Sample

The best way to check the features of FCKpackager is providing a small sample. Suppose we have the following code:

/*
* These constants must not be deployed. They are used in the development
* environment only, for readability and code comprehension.
*/
var BASIC_COLOR_RED = 1 ; // @Packager.Remove.Start var BASIC_COLOR_BLUE = 2 ; var BASIC_COLOR_WHITE = 3 ; // @Packager.Remove.End // Create the global "MyObject". var MyObject = new Object() ; // Get the color name. MyObject.GetColorName = function( colorId, upperCase ) { var name ; switch ( colorId ) { case BASIC_COLOR_RED : name = 'Red' ; case BASIC_COLOR_BLUE : name = 'Blue' ; case BASIC_COLOR_WHITE : name = 'White' ; } return upperCase ? name.toUpperCase() : name ; } // The following function has not much sense... it is just an example. MyObject.GetArray = function( value1, value2, value3, theLastWellDescriptiveArgument ) { var myArray = new Array() ; // Let's just push the arguments in the array. myArray.push( value1 ) ; myArray.push( value2 ) ; myArray.push( value3 ) ; myArray.push( theLastWellDescriptiveArgument ) ; // The following line must not be deployed. MyDebugFunction( myArray ) ; // @Packager.RemoveLine return myArray ; }

This is the result after processing it with FCKpackager:

var MyObject={};MyObject.GetColorName=function(A,B){var C;switch (A){case 1:C='Red';case 2:C='Blue';case 3:C='White';};return B?C.toUpperCase():C;};MyObject.GetArray=function(A,B,C,D){var E=[];E.push(A);E.push(B);E.push(C);E.push(D);return E;}

As we can see, the code is quite compact and difficult to read (another good thing about FCKpackager, for script protection).

Let's check what FCKpackager did with the original code:

Comments removal: one important thing to provide code quality and maintainability is good documentation, in the form of inline comments in the code. The problem is that comments take lots of space and have no real value at run-time. So, all comments have been removed.

White space minimalization: every single unnecessary white space character has been removed, including tabs and line breaks.

Variable renaming: to make your code easy to understand, it is preferable to use descriptive parameters and variable names like "documentName" instead of strange codes like "dn". This nice coding style choice take lots of space, so FCKpackager reduces their sizes to a single character.

// Original
MyObject.GetArray = function( value1, value2, value3, theLastWellDescriptiveArgument )
{
	var myArray = new Array() ;
	
	myArray.push( value1 ) ;
	myArray.push( value2 ) ;
	myArray.push( value3 ) ;
	myArray.push( theLastWellDescriptiveArgument ) ;
	
	return myArray ;
}

// Packed
MyObject.GetArray = function( A, B, C, D )
{
	var E = new Array() ;
	
	E.push( A ) ;
	E.push( B ) ;
	E.push( C ) ;
	E.push( D ) ;
	
	return E ;
}
		

Constants replacement: constants are nice because they make the code much more readable and understandable. They are a good coding style choice, but also take much space. You can configure FCKpackager to replace your constants with their real values in the code.

// Original
switch ( colorId )
{
	case BASIC_COLOR_RED :
		name = 'Red' ;

	case BASIC_COLOR_BLUE :
		name = 'Blue' ;

	case BASIC_COLOR_WHITE :
		name = 'White' ;
}

// Packed
switch ( colorId )
{
	case 1 :
		name = 'Red' ;

	case 2 :
		name = 'Blue' ;

	case 3 :
		name = 'White' ;
}

Object and Array declarations: it is nice to declare objects with "new Object()" and arrays with "new Array()". To save more space, FCKpackager wil ltransform them to "{}" and "[]" respectively.

// Original
var MyObject = new Object() ;
var myArray = new Array() ;

// Packed
var MyObject = {} ;
var myArray = [] ;

Processing directives: you can use the "@Packager.Remove" and "@Packager.RemoveLine" directives to remove blocks or lines of code when deploying.

Requirements

There is one important requirement in the coding style of the source scripts: all statements must be correctly terminated with semi-colon, except for brackets enclosed blocks, like functions and if statements (you may use it if you want it).

The FCKpackager executable runs on Windows operating systems. The PHP version runs on any platform containing PHP.