Riassence JSCompress
Description:
Simple C extension that compresses Javascript source with variables beginning with a underscore. This used to be a fixed part of the Riassence Framework, but it’s distributed as a separate gem now.
Usage:
require 'jscompress'
# Makes a JSCompress instance that compresses js source.
# The reserved_names are ignored in the input.
reserved_names = ['_dontCompressMe','_not_me_either']
jscompress = JSCompress.new( reserved_names )
# Builds indexes by reading source code.
# This ensures the best compression, because the shortest
# names are assigned to the most often used variables.
# It also ensures the different files have the same compressed
# variable names, so they can be called from one file to another.
js1 = File.read( 'big_js1.js' )
jscompress.build_indexes( js1 )
js2 = File.read( 'big_js2.js' )
jscompress.build_indexes( js2 )
js3 = File.read( 'big_js3.js' )
jscompress.build_indexes( js3 )
# Pack the source. Basically this means something like _longAndDescriptiveName -> _e
compressed_js1 = jscompress.compress( js1 )
compressed_js2 = jscompress.compress( js2 )
compressed_js3 = jscompress.compress( js3 )
# You can continue to build indexes after compression too:
js4 = File.read( 'big_js4.js' )
jscompress.build_indexes( js4 )
compressed_js4 = jscompress.compress( js4 )
# To free the indexes, use:
jscompress.free_indexes
Install:
-
sudo gem install jscompress
License:
Author: Domen Puncer <[email protected]>
License: MIT