缩小HTML / PHP [英] Minify HTML/PHP

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

问题描述

我使用gzip来压缩我的html / php文件以及js / css / etc。这减少了有效载荷相当不错,但我也想'缩小'我的标记的.html和.php页面。理想情况下,我想从一个.htaccess文件(我也做gzipping),而不是包括php到每个文件。

I'm using gzip to compress my html/php files along with js/css/etc. This reduces the payload quite nicely but I also want to 'minify' my markup of both .html and .php pages. Ideally I'd like to control this from a .htaccess file (where I also do the gzipping) rather than the having to include php to each file.

例如输出类似于 http://google.com http://www.w3-edge.com/wordpress-plugins/w3-total-cache/ http://css-tricks.com (均由W3 Total Cache插件为WordPress生成)。

I'd like the output to be like that of http://google.com or http://www.w3-edge.com/wordpress-plugins/w3-total-cache/ and http://css-tricks.com (both produced by W3 Total Cache plugin for WordPress).

任何人都可以推荐一个好的方法来做到这一点。

Can anyone recommend a good way to do this.

推荐答案

在示例中,缩小HTML输出几乎什么也不做。想想吧:Minifying是伟大的Javascript使用许多重复的变量和函数名称,作为缩小它们的主要事情之一是缩短他们和所有的引用。

Looking at the examples, minifying the HTML output does almost nothing. Think about it: Minifying is great for Javascript which uses many repeating variable and function names, as one of the main things minifying does is shorten them and all references to them.

另一方面,HTML标记没有变量或函数的概念。页面的大部分权重来自实际的标记和内容。这不能缩小。即使是形式变量也需要保留,因为它们的原始值必须由服务器正确处理。

HTML markup, on the other hand, has no concept of variables or functions. Most of the weight of the page is from actual markup and content. This cannot be minified. Even form variables need to be left alone as they must have their original values to be processed correctly by the server.

Gzipping已经非常有效地压缩了空白。在HTML中,这是真的可以做到的。

Gzipping will already compress the whitespace very efficiently. In HTML, this is really all that can be done.

此外,缩小PHP不适用,因为即使它有变量和函数,客户端。缩短名称对于在服务器上编译的内容没有性能好处。

Also, minifying PHP doesn't apply, because even though it has variables and functions, it is never sent to the client. Shortening the names has no performance benefit for something compiled on the server.

如果您决定缩小您的html,请查看WordPress插件的源代码。这就是开源的美。但是,我怀疑与Gzipping相比,收益可以忽略不计。

If you are determined to minify your html, check out the source code for the WordPress plugin that does it. That's the beauty of open source. However, I suspect the gains will be negligible as compared to Gzipping.

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

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