Compression experiments for JS13k
by David Goemans
• For JS13k, your delivered package needs to be 13kb or less
• It can be compressed but as a standard zip format
• This gives you about 90kb for actual code
• Many techniques available:
• JS Crush & Packer
• Zip Formats are restrictive
• Renaming tricks ( Globals )
• Very good for day-to-day compress
• Node/Grunt module makes for super easy integration
• Works out of the box, virtually never requires code changes
• Compresses very well, but not well enough
• With advanced compression, performs better than Uglify
• Minimal code changes required to make it compress well
• Compression is pretty good, but...
• Great compression with advanced compilation
• Requires code changes, especially related to global variables
• Some APIs not recognized by the compiler, such as PointerLock
• Best compression for zipping
~75kb code ~26kb code
JSCrush & Packer
• These are amazing pieces of technology.
• For best results, first run through Closure or Uglify with simple optimizations
• Since they're already so well compressed, they don't zip very well
• Not that useful for JS13k, and normal use, but great for JS1k!
• Zip has a few algorithms you can use, but only deflate is widely supported
• Deflate is based on Huffman trees, which works by detecting patterns
• Lots of the same text close together compresses well
• This is why JSCrush/Packer doesn't zip very well!
• Each file generates some overhead
• Less files with shorter names is best
• Remember, reserved words can't be minified.
• Re-define common long reserved names and attach to a global object
$.minFilterVar = 'TEXTURE_MIN_FILTER';
• Seems longer at first, but compresses really well!
Lead developer @ BoosterMedia Game Studio
JS13k Project code:
Extra info on zip compression: