How to minify HTML?

2019-02-08 10: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)

3条回答
ゆ 、 Hurt°
2楼-- · 2019-02-08 10:36

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.

查看更多
老娘就宠你
3楼-- · 2019-02-08 10:52

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...

查看更多
做个烂人
4楼-- · 2019-02-08 11:00

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

查看更多
登录 后发表回答