Created
January 22, 2013 16:22
-
-
Save libo1106/4595990 to your computer and use it in GitHub Desktop.
Compress CSS with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Minify.css.php?f=style.css | |
<?php | |
//重定义header | |
ob_start ("ob_gzhandler"); | |
header("Content-type: text/css; charset=UTF-8"); | |
header("Cache-Control: must-revalidate"); | |
$offset = 60 * 60 ; | |
$ExpStr = "Expires: " . | |
gmdate("D, d M Y H:i:s", | |
time() + $offset) . " GMT"; | |
header($ExpStr); | |
//压缩过程 | |
$rawCss = include($_GET[f]); | |
$minCss = Compress($rawCss); | |
echo($minCss); | |
?> | |
配置mod_rewrite之类的,把style.css请求,重定向到Minify.css.php?f=style.css | |
html中正常调用css文件 | |
<link rel='stylesheet' type='text/css' href='css/style.css' /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment