问题
Is there some tool (or Rails itself) that can minify HTML (like what Jammit does for CSS and JS files) ?
Secondarily, 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)
回答1:
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...
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/5768362/how-to-minify-html