How to minify HTML?

瘦欲@ 提交于 2019-12-18 12:58:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!