|
|
||||
|
||||
|
|
|
|
FCKpackager - JavaScript Compressor ToolFCKpackager is a simple command line application which compacts and optimizes one or many JavaScript source files on fewer and smaller files. DownloadFCKpackager is currently available at our SVN only. To download it, just follow this link: The PHP version of it is also available for download here: To execute the PHP version, just run it in the command line with PHP: php fckpackager.php Features: Simple SampleThe best way to check the features of FCKpackager is providing a small sample. Suppose we have the following code: /* 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. RequirementsThere 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. |
|
|