How to minify HTML?
Is there some tool (or Rails itself) that can minify HTML (like what Jammit does for CSS and JS files) ?
Secondarily开发者_如何学Go, what is the best practice here, and is it even worth minifying the html? (this is for a site that will be served to mobile phones, so keeping weight down is important)
Well, you can remove most white space by using the HAML gem and the following lines in your config/application.rb
file:
Haml.init_rails(binding)
Haml::Template.options[:format] = :html5
Haml::Template.options[:ugly] = true
More information: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#ugly-option
Enabling compression at HTTP level will serve you much more than minifying HTML, however tidy is good to apply transformations to HTML, including removing extraneous spaces , comments, etc...
You can use http://prettydiff.com/?m=minify&html to minify your HTML.
Minifying HTML is extremely complicated and easily misunderstood. True minification involves removing comments and all unnecessary white space from the syntax, which would include an white space in your content, so be sure you are using a tool that knows what it is doing.
精彩评论