FFI Javascript minifier
C++ Ruby C
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ext
lib
.gitignore
README.textile
Rakefile
VERSION
jsmin-ffi.gemspec

README.textile

FFI Javascript minifier

Description

This library was created in order to provide a reasonably fast Javascript
minifier on JRuby platform.
Both native Java and Ruby implementations were found to be in several orders
of magnitude slower.
The only change from the original C implementation, is that it was changed
to C++ (in order to make global variables become instance variables),
and it works with buffers rather than stdin/stdout now.

Synopsis

 require 'jsmin_ffi'
 input = IO.read('prototype.js')
 begin
   output = JsminFFI.minify!(input)
   File.open('output.js', 'w') {|f| f.write(output)}
 rescue Jsmin::ParseError => e
   $stderr.puts "Cannot minify: #{e}"
 end

or use a native extension:


require ‘Jsmin’
input = IO.read(‘jquery.js’)
begin
output = Jsmin.minify(input)
File.open(‘output.js’, ‘w’) {|f| f.write(output)}
rescue Jsmin::ParseError => e
$stderr.puts “Cannot minify: #{e}”
end

Bugs

The memory allocated in the C++ code might not be freed when using FFI.
It depends on how FFI handles the returned char*.

See also

For the original implementation, please see:
http://www.crockford.com/javascript/jsmin.html