这是用PHP压缩多个CSS的流行片段。如何改进此代码以使用PHP组合/压缩CSS
<?php
header('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", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
/* your css files */
include('master.css');
include('typography.css');
include('grid.css');
include('print.css');
include('handheld.css');
ob_end_flush();
?>
看着代码,我可以看到它只会压缩文件,但不会合并它们。我如何调整它以合并文件呢?
“我可以看到它只会压缩文件,但不会合并它们” - 它会将它们结合起来(它不会压缩它们,它会缩小它们,而且它看起来很像就像它不会生成有用的缓存控制标题,这可能最终导致效率降低,然后加载各种文件)。 – Quentin
为什么降级这个问题。它很糟糕吗?你能帮助改进这个代码吗? – Daniel