PHP 启用Gzip 压缩进行优化

确定服务器支持gzip compression
Use PHP to Gzip CSS files  http://papermashup.com/use-php-to-gzip-css-files/
Compress CSS and JavaScript with PHP http://wp-mix.com/compress-gzip-deflate-css-javascript/
Enabling Gzip Compression of PHP, CSS, and JS Files Without mod_deflate
http://www.warpconduit.net/2010/10/23/enabling-gzip-compression-of-php-css-and-js-files-without-mod_deflate/
Minify helper for cakephp http://bakery.cakephp.org/articles/_k10_/2009/01/17/minify-helper-for-cakephp
Using PHP Minify in CakePHP http://7shifts.com/using-php-minify-in-cakephp/
这篇文章的问题:
1. $min_cachePath = TMP . ‘/minify’;  这里要改为:$min_cachePath = TMP . ‘minify’;
2. 在app/tmp建立minify文件夹。
3. 修改函数:同时里面的e方法改成echo方法。

4.  这里两个变量不存在,要增加app/Vendor/min/config.php
$min_serveOptions[‘rewriteCssUris’] = false;
$min_serveOptions[‘minifierOptions’][‘text/css’][‘prependRelativePath’] = WEBROOT_URL . ‘css/theme/’;
5.清理缓存后第一次刷新没问题,第二次刷新就无法下载压缩后的文件,为何?
$path .= ($ext . ‘/’ . $asset . “.$ext”.”&rt=”.rand(100000,999999)); 这个方法加上随机数,能解决这个问题,但是,客户端能否缓存?

Compress CSS and JavaScript with PHP
CSS, JavaScript131
Quick snippets for compressing CSS and JavaScript with PHP’s ob_gzhandler, which will gzip or deflate content depending on browser support.

Compress CSS content
To compress CSS content, add the following code to any PHP file (i.e., .php extension):

Compress JavaScript content

That’s all there is to it, and to further reduce file size, you should run the actual CSS/JavaScript code through the minifier of your choice.

For more information about either of these methods, check out my articles at Perishable Press:

Compressed CSS Compression http://perishablepress.com/compressed-css-compression/
Compressed JavaScript Compression http://perishablepress.com/compressed-javascript-compression/