Skip to content

Instantly share code, notes, and snippets.

@libo1106
Created January 22, 2013 16:22
Show Gist options
  • Save libo1106/4595990 to your computer and use it in GitHub Desktop.
Save libo1106/4595990 to your computer and use it in GitHub Desktop.
Compress CSS with PHP
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