Minify Your HTML from Sinatra

| Comments

There are gzip compression options available but when I looked at this a long time ago I found that the extra server load to compress (with out caching) and the extra delay in the browser to decompress was not worth the few bytes it saved and lead to longer times before seeing the fully rendered page.

Minification or minifying is more about removing white space, in the case of javascript it can also optimise variable names. For html we would not want to do that unless our css was going to be converted to match exactly.

After a little digging and trying a few gems which failed to set there dependancies correctly and even required 'pp'*, I found TidyFFI.

  • Really useful for debugging but I do not think has a place in deployed code.

Minify HTML

gem install TidyFFI


get '/' do
  erb :'about'

After :

require 'tidy_ffi'
get '/' do erb :'about' ).clean