如何缩小HTML代码? [英] How to Minify HTML code?

查看:174
本文介绍了如何缩小HTML代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的想法是以某种方式在服务器端缩小HTML代码,所以客户端接收的字节更少。



我的意思是 minify?



不压缩。例如,更像是jQuery创建者使用 .min .js 版本。换句话说,我需要删除不必要的空格和换行符,但我不能删除HTML的更改(例如,删除段落中实际单词之间的空格)。



有什么工具可以做到吗?我知道有 HtmlPurifier 。它能够做到吗?任何其他选项?



请不要提供regex'ies。我知道只有Chuck Norris可以解析HTML。您可以将HTML代码解析为一个DOM树(它应该在节点中保留内容空白),然后串行化它回到HTML,没有任何美化空间。


My idea is to somehow minify HTML code in server-side, so client receive less bytes.

What do I mean with "minify"?

Not zipping. More like, for example, jQuery creators do with .min.js versions. In other words, I need to remove unnecessary white-spaces and new-lines, but I can't remove so much that presentation of HTML changes (for example remove white-space between actual words in paragraph).

Is there any tools that can do it? I know there is HtmlPurifier. Is it able to do it? Any other options?

P.S. Please don't offer regex'ies. I know that only Chuck Norris can parse HTML with them. =]

解决方案

You could parse the HTML code into a DOM tree (which should keep content whitespace in the nodes), then serialise it back into HTML, without any prettifying spaces.

这篇关于如何缩小HTML代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆