From:
http://www.fiftyfoureleven.com/sandb...s-gzip-method/
1. You save this snippet as gzip-css.php:
Code:
<?php
ob_start ("ob_gzhandler");
header("Content-type: text/css");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
2. Add this snippet to your htaccess:
Code:
AddHandler application/x-httpd-php .css
php_value auto_prepend_file gzip-css.php
Make sure that if you do this that your CSS files are in a directory all by themselves.
Since you probably don't want to do that, and you want your JS gzipped you should do the following:
Keep your htaccess rule of:
Code:
AddType application/x-httpd-php .php .css .js
Then put this at the start of your CSS files:
Code:
<?php
ob_start ("ob_gzhandler");
header("Content-type: text/css");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
and this at the start of your JS files:
Code:
<?php
ob_start ("ob_gzhandler");
header("Content-type: text/javascript");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
Remember that we need to make sure that our CSS files, though being parsed by PHP need to be sent with a MimeType of text/css or it won't display in stricter browsers, and similarly for JS.
Bookmarks