JavaScript and HTML Code Compactor.
Download it from here

The Code Compactor is a tool for reducing the size of JavaScript files so that they will download quicker and consume less memory. I developed it principally for my own use but any iTV or web developer may find it useful whenever files need to be optimised for size and memory footprint.
It does this in a number of ways, many of which are configurable by the coder to suit their requirements. However it was written to suit my own coding style and so has certain limitations.
So far it has been tested on Windows 2000, Windows 2000 Professional and Windows 98SE and runs fine.
NOTE that this is the first release and is somewhat of a BETA PRODUCT. I especially welcome bug reports (break it if you can ;-) and suggestions for future enhancements.
Code Compactor v2

Removing Spaces

By default, Compactor removes all tab characters and unnecessary spaces from your code. Certain spaces are necessary however, and spaces after the following keywords are always preserved:
  • new
  • var
  • else
  • return
  • function
  • Spaces within comments, 'single quotes' and "double quotes" are also preserved.
In addition you can specify a list of keywords after which a space must be preserved. The delimiters are SPACE, SEMI-COLON and COMMA.

Removing Lines

By default the Compactor will remove all blank lines and lines containing only spaces and tab characters. In addition to this it can remove:
  • All lines containing the keyword "debugtext"
  • All lines containing "//" (an inline comment)
  • Any /* block commented */ code
Be Careful!
  1. STB interpreters can be fussy about empty "for" loops and the like. If you have any loops containing only debugtext or a comment this can be a problem.
  2. You must adopt a coding style which only puts inline comments above or below the actual code as lines with inline comments are removed completely.
  3. Only lines of up to 199 characters can be handled.

Appending Files

Multiple files can be loaded into the Compactor and output to a single file. This can save memory on a Set-Top Box but often the files must be loaded into the STB memory in a certain order. Check the "Append Multiple JS Files" checkbox and use the "FILE/Open JS File" menu option. Once chosen the files can be dragged into the correct order using the LEFT mouse button. Any loaded files not required for the build can be removed by RIGHT-CLICKING on them. Of course you can also process one file at a time. There is an option to add file separators (consisting of each file's name) between each of the appended files to help with any post-compilation debugging.

Processing Files

When you are ready to process your files, click the RUN menu option. When the operation is complete you will be prompted for a filename to save your files to.

HTML Files

You can also reduce the weight of HTML pages by choosing the "FILE/Open HTML File" meu option. This will clean all html-style comments ONLY and will handle comments that span more than line.

Future Enhancements

Mail your suggestions to me HERE


This program is provided "as is" without express or implied warranty. The author disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness, in no event shall the author Mark Serlin be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortuous action, arising out of or in connection with the use or performance of this software. Any damage to or corruption of your source code is your own responsibility so make sure you have READ and UNDERSTOOD these instructions! The Compactor was developed on Windows 2000, runs fine on 2K Professional and 98SE and should run fine on other platforms. However no liability either express or implied is accepted by me for any damage caused to computers or operating systems in the normal course of operating this software.


For the time being this product is distributed free but I ask you not to distribute it to friends and colleagues but to direct them to here so that they have the opportunity to read the instructions for themselves.


  1. Some versions may not start due to a reportedly missing file. The program is hunting in the registry for the last file opened and doesn't handle the lack of a file correctly. Later versions do not have this problem, so download the latest version from this page.
  2. Some versions of Compactor may start but not be visible, though there is a taskbar button. It is actually appearing off-screen! This is due to the program being compiled on a 2-screen workstation (whoops!). The fix is to hit ALT-SPACE (brings up the main window menu though you won't be able to see it) followed by M (Move), then hold down the left-arrow key to bring the interface into view.
  3. var somearray = someString.split(" ");
    This line of code fooled it for some reason resulting in an unterminated string literal error, in other words the line ended up like this:
    var somearray = someString.split("); with all the rest of the code thinking it was still the string :(
    The space in the quotes should have been ignored and the string terminated properly.
    This error only seems to happen with a single space in quotes - " ". I'll fix it when I can, meanwhile be aware of this one.
    Tip - if your editor does syntax highlighting this kind of error is very easy to spot.

Other problems

Lines of code may be removed because there is an inline comment on the same line:
var card = 1; // Reset the deck
The interpreter usually complains if there is an empty for loop, for instance where the only thing in the block was a debugtext statement:
    debugtext(myArray[i].name + ", " + myArray[i].value) - this line removed!

Be aware that the Compactor does write some stuff to your registry and as there's no installer, they get left behind. It's only a few strings which save your options for you anyway, and they can be deleted using regedit. You'll find them in HK_CURRENT_USER/Software/Northview and HK_USERS/Software/Northview or just search for keys of name Northview and delete them. If you're worried about a few extra bytes. Future releases may have an uninstaller built in so (coming soon) Register For Upgrades!

Issues, comments or bug reports they can be sent to me at this address. There are quite a few user-friendly features missing from this release, I plan to develop the Compactor once I am sure the code is rock-solid, and for this I would appreciate your help.