php压缩多个CSS/JS文件

来源:互联网 发布:java中%是什么意思 编辑:程序博客网 时间:2024/05/16 21:18
1:压缩css<?phpheader('Content-type: text/css');ob_start("compress");function compress($buffer) {/* remove comments */    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);    /* remove tabs, spaces, newlines, etc. */    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);    return $buffer;}  /* your css files */include('galleria.css');include('articles.css');ob_end_flush();


使用:

<link href="compress.php" rel="stylesheet" type="text/css" /><span id="tester">test</span>
2:压缩js

利用jsmin类

来源:http://code.google.com/p/minify/


header('Content-type: text/javascript');require 'jsmin.php';echo JSMin::minify(file_get_contents('common.js') . file_get_contents('common2.js'));


原创粉丝点击