Home > php教程 > php手册 > php压缩多个CSS/JS文件

php压缩多个CSS/JS文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-26 08:21:00
Original
905 people have browsed it

1:压缩css

<?php   
header(&#39;Content-type: text/css&#39;);   
ob_start("compress");   
function compress($buffer) {   
/* remove comments */   
$buffer = preg_replace(&#39;!/*[^*]**+([^/][^*]**+)*/!&#39;, &#39;&#39;, $buffer);   
/* remove tabs, spaces, newlines, etc. */   
$buffer = str_replace(array("rn", "r", "n", "t", &#39;  &#39;, &#39;    &#39;, &#39;    &#39;), &#39;&#39;, $buffer);   
return $buffer;   
}     
   
/* your css files */   
include(&#39;galleria.css&#39;);   
include(&#39;articles.css&#39;);
ob_end_flush();
Copy after login

使用:

<link href="compress.php" rel="stylesheet" type="text/css" /><span id="tester">test</span>
Copy after login

2:压缩js,利用jsmin类:

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

header(&#39;Content-type: text/javascript&#39;);   
require &#39;jsmin.php&#39;;   
echo JSMin::minify(file_get_contents(&#39;common.js&#39;) . file_get_contents(&#39;common2.js&#39;));  //phprm.com
Copy after login

                               


Related labels:
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
Latest Issues
PHP code not applying CSS stylesheet
From 1970-01-01 08:00:00
0
0
0
Using Typecho+Nginx+php-fpm to load css error 502
From 1970-01-01 08:00:00
0
0
0
Isn’t English very good to learn?
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template