Reputation: 15506
found a nice program in this discusson that combines CSS files into one, to speed up and fasten the CSS load. It works and makes all my css files into one tiny heap, BUT the page shows as text (the webpage becomes a css file, apache thinks) what can be wrong?
What i did: I saves the below script as a php file and included that into my page, and changed the urls to the css files with theirs. The css loads fine, but the WEBPAGE shows up as plain text into the browser! while all css is there and the rest of the php generated items too, only thing is the browser things it should load is as plain text, instead of html website... Any clues?
<?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", "\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();
?>
Furthermore improvements could be made later to even improve its strength, once working:
"; }"
> "}"
(2 chars)
"{ "
> "{"
(1 char)
" {"
> "{"
(1char)
" :"
> ":"
(1 char)
": "
> ":"
(1 char)
" ,"
> ","
(1 char)
", "
> ","
(1 char)
" ("
> "("
(1 char)
"( "
> "("
(1 char)
" )"
> ")"
(1 char)
") "
> ")"
(1 char)
Upvotes: 1
Views: 247
Reputation: 8851
How are you including that snippet?
At a guess, I'd imagine that should be it's own file and included via <link rel="stylesheet" type="text/css" href="./css.php" />
or similar. If you pasted that straight into index.php, you're setting the MIME type of it's output to text/css (via the header()
), hence the plaintext.
Upvotes: 3