Airgun
¶ ↑
This gem provides a simple Ruby interface to compress HTML, JS, and CSS, including embedded JS and CSS. This is useful for compressing static web content for size and obfuscation.
require 'airgun' puts Airgun::html 'file.htm' args = { :outfile => 'compressed.htm', :jscompressor => :closure, :erb => true, :compressjs => true, :compresscss => false } Airgun::html 'file.htm', args
HTML compresson is provided by the html_compressor gem after parsing with Nokogiri}[]. CSS compression is provided by the {YUI Compressor. JS compression is provided by Google’s Closure Compiler.
Documentation¶ ↑
Airgun::html file, args
By default this method returns the compressed HTML as a string.
Possible arguments:
-
:outfile - Write the compressor’s output to this file.
-
:exclude - Exclude the CSS and JS linked in the HTML page that match one of the filenames in this list.
-
:jscompressor - Either :closure or :yui, defaults to :closure.
-
:fragment - Either true or false. Don’t parse with Nokogiri prior to compression, this disables JS and CSS compression.
-
:erb - Either true or false. Run the files through ERB before compression.
-
:compressjs - Either true or false, defaults to true.
-
:compresscss - Either true or false, defaults to true.
Airgun::js file, args
By default this method returns the compressed JS as a string.
Possible arguments:
-
:compressor - Either :closure or :yui, defaults to :closure.
-
:outfile - Write the compressor’s output to this file.
-
:erb - Run the file through ERB prior to compression
Airgun::css file, args
By default this method returns the compressed CSS as a string.
Possible arguments:
-
:outfile - Write the compressor’s output to this file.
-
:erb - Run the file through ERB prior to compression