Home > Backend Development > PHP Tutorial > 【性能优化】PHP代码输出压缩后HTML

【性能优化】PHP代码输出压缩后HTML

WBOY
Release: 2016-06-23 13:27:23
Original
1019 people have browsed it

此操作也可以归结在性能操作类别上,虽然效果不是很明显,但在一定情况下起得很好的作用,下面理几点使用该方法的原因

大流量访问页面压缩代码节省RMB,百度首页也这么做。O(∩_∩)O哈哈~

个人爱好,性能强迫症。

源代码混乱(掩饰网站前端用户编码结构习惯,现今没啥用)

.....

不多说了,主要给喜欢倒腾代码的朋友看看。

function compress_html($string){		return ltrim(rtrim(preg_replace(array(		"/> *([^ ]*) *</",		"/<!--[^!]*-->/",		"'/\*[^*]*\*/'",		"/\t/","/\n/",		'/>[ ]+</',		"/\n+/"		),array(		">\\1<",		'',		'',		'',"\r",		'><',		' '		),$string)));	}
Copy after login

html内容要从缓冲区获取,具体方式根据自己程序设计框架决定。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template