每当用户像这样进入页面时,我都会从文件中生成 CSS:
<?php
header("Content-type: text/css");
$styles = array(
'default',
'reset',
'notifybar',
'jqui'
);
if (isset($_GET['page'])) {
if (file_exists('styles/' . trim($_GET['page']) . '.css'))
$styles [] = $_GET['page'];
switch ($_GET['page']) {
case "main":
$styles [] = "treeview";
$styles [] = "buttons";
$styles [] = "wmd";
$styles [] = "qa";
$styles [] = "pretify";
$styles [] = "code";
$styles [] = "msgBoxes";
break;
case "payments":
$styles [] = "tables";
break;
}
}
foreach ($styles as $style) {
include 'styles/' . $style . '.css';
}
?>
HTML像这样得到CSS
<link rel="stylesheet" href="design/css.php?page=<?= $pgdata['token'] ?>" type="text/css" media="screen" />
我有两个问题:
- 我可以缓存 css 文件以获得更好的性能吗?如果是,那么如何?
- 如何在输出期间压缩 css 文件?我的意思是类似混淆:删除空换行符,空格..换句话说,创建css的生产版本。如果可能的话,帮我做缓存。提前谢谢