I've got over some tutorials on how to gzip a css file in which you create a public php file to include css files with compression. The problem is I cannot get it to cache my css files. I'm using firebug for reference and I've actually tried using the same code to compress some javascript and it caches it fine.
Here is the code:
if(extension_loaded('zlib')){ ob_start('ob_gzhandler'); } $offset = 60 * 60 * 24 * 31; header('Content-type: text/css'); header ('Cache-Control: max-age=' . $offset . ', must-revalidate'); header ('Expires: ' . gmdate ("D, d M Y H:i:s", time() + $offset) . ' GMT'); ob_start("compress"); function compress($buffer) { // Remove Comments, White Space, End ;'s $buffer = preg_replace('#/\*.*?\*/#s', '', $buffer); $buffer = preg_replace('/\s*([{}|:;,])\s+/', '$1', $buffer); $buffer = preg_replace('/\s\s+(.*)/', '$1', $buffer); $buffer = str_replace(';}', '}', $buffer); $buffer = str_replace(' {', '{', $buffer); return $buffer; } include('global.css'); if(extension_loaded('zlib')){ ob_end_flush(); }
Then I'm simply referencing my php file as a css document on other pages. As you can see I've tried adding max age to the mix which also proves unsuccessful.
Here are the response headers
Date Tue, 21 Jul 2009 19:59:19 GMT Server Apache/1.3.41 (Darwin) PHP/4.4.9 X-Powered-By PHP/4.4.9 Cache-Control max-age=2592000, must-revalidate Expires Thu, 20 Aug 2009 19:59:19 GMT Content-Encoding gzip Vary Accept-Encoding Keep-Alive timeout=15, max=93 Connection Keep-Alive Transfer-Encoding chunked Content-Type text/css
Is there anything I'm missing, or a better way to go about doing this?
Thanks,
EDIT:
A script that detects whether or not the file has been changed & sending a 304 if it hasn't, in combination with proper headers has solved this problem.
Arthur