- 浏览: 3362144 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (1633)
- Java (250)
- Android&HTML5 (111)
- Struts (10)
- Spring (236)
- Hibernate&MyBatis (115)
- SSH (49)
- jQuery插件收集 (55)
- Javascript (145)
- PHP (77)
- REST&WebService (18)
- BIRT (27)
- .NET (7)
- Database (105)
- 设计模式 (16)
- 自动化和测试 (19)
- Maven&Ant (43)
- 工作流 (36)
- 开源应用 (156)
- 其他 (16)
- 前台&美工 (119)
- 工作积累 (0)
- OS&Docker (83)
- Python&爬虫 (28)
- 工具软件 (157)
- 问题收集 (61)
- OFbiz (6)
- noSQL (12)
最新评论
-
HEZR曾嶸:
你好博主,这个不是很理解,能解释一下嘛//左边+1,上边+1, ...
java 两字符串相似度计算算法 -
天使建站:
写得不错,可以看这里,和这里的这篇文章一起看,有 ...
jquery 遍历对象、数组、集合 -
xue88ming:
很有用,谢谢
@PathVariable映射出现错误: Name for argument type -
jnjeC:
厉害,困扰了我很久
MyBatis排序时使用order by 动态参数时需要注意,用$而不是# -
TopLongMan:
非常好,很实用啊。。
PostgreSQL递归查询实现树状结构查询
确定服务器支持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/
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方法。
function _path($assets, $ext){ if(!is_array($assets)){ $assets = array($assets); } $path = $this->webroot . "min-" . $ext . "?f="; foreach($assets as $asset){ if(strpos($asset,"/")===0){ //如果以为/开头,表示这个文件不是在规定的地方里面,所以要特殊处理 $path .= (substr($asset,1) . ".$ext,"); }else{ $path .= ($ext . '/' . $asset . ".$ext,"); } } return substr($path, 0, count($path)-2); }
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):
<?php // compress CSS header("content-type: text/css; charset: utf-8"); header("cache-control: must-revalidate"); $offset = 365 * 24 * 60 * 60; $expire = "expires: ".gmdate("D, d M Y H:i:s", time() + $offset)." GMT"; header($expire); if(!ob_start("ob_gzhandler")) ob_start(); ?> <?php // replace this line with as much CSS code as you want ?> <?php ob_flush(); ?>
Compress JavaScript content
<?php // compress JS header("content-type: text/javascript; charset: UTF-8"); header("cache-control: must-revalidate"); $offset = 365 * 24 * 60 * 60; $expire = "expires: ".gmdate("D, d M Y H:i:s", time() + $offset)." GMT"; header($expire); if(!ob_start("ob_gzhandler")) ob_start(); ?> <?php // replace this line with as much JavaScript code as you want ?> <?php ob_flush(); ?>
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/
发表评论
-
php图片添加文字水印实现代码
2016-03-16 13:13 1075http://my.oschina.net/zyt1978/b ... -
借助phpmailer使用gmail和163邮箱发送邮件
2016-01-16 14:03 4365http://www.solagirl.net/phpmail ... -
自定义Access-Control-Allow-Origin策略以解决字体文件跨域权限问题
2014-11-23 22:43 1922http://yuguo.us/weblog/access-c ... -
推荐 7 款类似Google Analytics 的开源程序
2014-11-14 23:30 4136http://www.aips.me/google-analy ... -
piwik安装过程
2014-11-13 23:08 916http://blog.csdn.net/gudaoqianf ... -
使用 PHP 获取并解析 JSON 显示在页面中
2014-11-05 22:44 3389http://www.qianxingzhem.com/pos ... -
PHP获得IP
2014-11-02 15:06 1085<?php function getIP() /* ... -
CakePHP的全局常量及方法
2014-10-28 14:32 1158http://docs.30c.org/cakephp/glo ... -
php日期
2014-10-21 21:04 860http://php.net/manual/zh/functi ... -
PHP生成各种验证码和Ajax验证
2014-10-08 13:47 933http://www.helloweba.com/view-b ... -
计算一段日期内的周末天数的php代码(星期六,星期日总和)
2014-10-07 14:48 2240http://www.jb51.net/article/208 ... -
PHP中出现Notice: Undefined index的三种解决办法
2014-09-14 17:18 2444http://blog.csdn.net/stellaah/a ... -
细说websocket - php篇
2014-07-24 21:04 1174http://www.cnblogs.com/hustskyk ... -
CakePHP log(日志)操作
2013-12-07 23:19 1317http://luzl.iteye.com/blog/6537 ... -
使用PHP缩略图和剪切图
2013-11-28 23:05 1851API: resource imagecreatetrueco ... -
几个jQuery的图片裁剪插件
2013-11-28 21:02 4208http://hi.baidu.com/coffeant/it ... -
提升CakePHP网页应用速度的八大方法
2013-11-26 10:19 1147http://www.21haolou.com/article ... -
PHP URL 重定向 的三种方法
2013-11-26 10:06 1176http://my.oschina.net/qingyi090 ... -
PHP如何实现整除
2013-11-24 00:48 3358http://www.zhixing123.cn/php/27 ... -
PHP截断包含汉字不产生乱码的方法
2013-11-21 22:29 1018PHP截取汉字乱码问题解决方法mb_substr函数的应用 h ...
相关推荐
网页开启gzip压缩以后,其体积可以减小20%~90%,可以节省下大量的带宽,从而减少页面响应时间,提高用户体验。 php配置改法: 复制代码 代码如下: zlib.output_compression = On ;开启gzip功能 zlib.output_...
本文实例讲述了php使用curl获取header检测开启GZip压缩的方法。分享给大家供大家参考,具体如下: 获得网页header信息,是网站开发人员和维护人员常用的技术。网页的header信息,非常丰富,非专业人士一般较难读懂和...
开启TOMCAT6的GZIP压缩功能,在客户端请求网页后,从服务器端将网页文件压缩,再下载到客户端,由客户端的浏览器负责解压缩并浏览。相对于普通的浏览过程HTML ,CSS,Javascript , Text ,它可以节省40%左右的流量。...
一般而言,页面文件开启gzip压缩以后,其体积可以减小60%~90%,对于文字类站点,可以节省下大量的带宽与用户等待时间。但是不论是iis还是apache默认都只压缩html类静态文件,对于php文件需要模块配置才可支持(iis...
2.开启gzip 利用apache mod_deflate module 开启gzip ...3.设置需要gzip压缩输出的类型 json的输出类型是application/json,所以可以这样设置 在httpd.conf的<Directory></Directory>中加入 <IfModule m
主要介绍了php curl中gzip的压缩性能测试,结合实例形式分析了php使用curl的gzip压缩耗时与效率,需要的朋友可以参考下
Gzip压缩传输能更加有效节约带宽流量。他先把文本压缩为.gz然后传输给浏览器,最后由浏览器负责解压缩呈现给用户。 老版本的浏览器可能不能显示,但是现在大多数浏览器都能显示。 启用Gzip传输首先要求PHP4.0.5以后...
因为我有过相关经验马上发现是网站开启了gzip而file_get_contents 获得的是压缩过的页面,而不是解压过的页面(不知道是不是要file_get_conttents 请求网页时带上相应的参数,直接获得没有被gzip压缩过的网页?...
本篇文章是对PHP开启gzip页面压缩实例进行了详细的分析介绍,需要的朋友参考下
对于部署在Linux服务器上的PHP程序,在服务器支持的情况下,我们建议你开启使用Gzip Web压缩,以前脚本之家介绍了iis中的开启方法,这篇文章主要介绍了linux中apache的开启方法
要实现GZIP压缩页面需要浏览器和服务器共同支持,实际上就是服务器压缩,传到浏览器后浏览器解压并解析。浏览器那边不需要我们担心,因为现在绝大多数浏览器都支持解析GZIP过的页面。我们只要把页面在服务器端压缩再...
今天在调取一家商城的页面信息时候,使用...类似的信息,即Content-Encoding为gzip,即该站点开启了gzip压缩。这里的解决方案有多种,当然如果你使用file_get_contents的话,可以这样修改: 复制代码 代码如下: file
使用php判断页面或图片是否经过gzip压缩方法 1.使用get_headers 页面内容 <?php ob_start('ob_gzhandler'); // 开启gzip,屏蔽则关闭 $data = array( array('name'=>'one','value'=>1), array('name'=>'two',...
Gzip可以压缩网页大小从而达到加速打开网页的速度,目前主流的浏览器几乎都支持这个功能,但开启Gzip是需要服务器支持的,在这里我们简单的使用php来判断服务器是否支持Gzip功能。 新建一个php类型文件,可命名为...