Skip to content

Instantly share code, notes, and snippets.

@mib32
Created November 29, 2017 21:48
Show Gist options
  • Save mib32/daac8d10974d1abe130a77202c2dc2e1 to your computer and use it in GitHub Desktop.
Save mib32/daac8d10974d1abe130a77202c2dc2e1 to your computer and use it in GitHub Desktop.
Performance comparison of JS and CSS compressors
#!/usr/bin/env ruby
require 'sprockets'
require 'uglifier'
require 'closure-compiler'
require "yui/compressor"
require 'sass-rails'
require 'httparty'
jquery = HTTParty.get("https://code.jquery.com/jquery-git.js").body
css = HTTParty.get("https://code.jquery.com/ui/1.11.4/themes/black-tie/jquery-ui.css").body
uglifier = Sprockets::UglifierCompressor.call({data: jquery})
# yui_js = YUI::JavaScriptCompressor.new.compress(jquery)
closure = Closure::Compiler.new.compress(jquery)
closure_advanced = Closure::Compiler.new(:compilation_level => 'ADVANCED_OPTIMIZATIONS', :process_common_js_modules => true).compress(jquery)
# jsmin: This project is unmaintained. I stopped using it years ago. You shouldn't use it. You shouldn't use any version of JSMin. There are much better tools available now.
sass = Sprockets::SassCompressor.call({data: css})
yui_css = YUI::CssCompressor.new.compress(css)
# cssmin Ruby library for minifying CSS. Unmaintained.
puts 'JS'
puts "Original: #{jquery.length}"
puts "Uglifier: #{uglifier.length}"
# puts "YUI: #{yui_js.length}"
puts "Closure (simple): #{closure.length}"
puts "Closure (advanced): #{closure_advanced.length}"
puts "===================================="
puts "CSS"
puts 'Original: ' + css.length.to_s
puts "SASS: #{sass.length}"
puts "YUI: #{yui_css.length}"
puts sass
puts '---'
puts yui_css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment