Small snippet to compress HTML in Ruby. Returning from function is a string with the basic compressed HTML. def compress(html) html.gsub!(/\n+/,'') html.gsub!(' ', '') html.gsub!('> <', '><') puts html end