Home  >  Article  >  php教程  >  PHP中,JS和CSS优化工具Minify的使用方法

PHP中,JS和CSS优化工具Minify的使用方法

WBOY
WBOYOriginal
2016-06-13 09:35:011137browse

为减少HTTP请求,我们往往需要合并和压缩多个JS和CSS文件,下面记录下网上关于实现这个功能的PHP源码以及开源项目Minify的使用方法

一、实现合并和压缩多个JS和CSS文件的代码请参考

1、一句命令快速合并JS和CSS文件

2、PHP合并多个JS和CSS文件,减少HTTP请求(原型) 

二、Minify的使用方法

1、从code.google.com/p/minify/下载最新版Minify并解压缩,将"min"文件夹连同里面的内容一起复制到DOCUMENT_ROOT目录下(即网站跟目录)。

可以修改文件夹名"min"

2、在"min/groupsConfig.php"里配置g参数

return array(
  // 'js' => array('//js/file1.js', '//js/file2.js'),
  // 'css' => array('//css/file1.css', '//css/file2.css'),
);

3、在网页中按照如下方式引用就可以了:

<script type="text/javascript" src="/min/g=js&20140519"></script>

后面的数字可以用更新日期来作标志,"min"和步骤1里的名称对应。

4、性能优化,请参考code.google.com/p/minify/wiki/CookBook

注意:

1、需要将httpd.conf里的rewrite_module模块开启

2、开发过程中,可以将调试模式开启,开发完毕后再将调试模式关闭,可以利用火狐浏览器的firebug来查看

<span>$min_allowDebugFlag</span> = <span>true</span>

 

 

 

 

Statement:
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