ob_start within CSS.php

I’ve placed the following code in my CSS file:

<?php 
ob_start("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " . 
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>

As expected, I renamed the extension of the CSS file to that of “.php” but I cannot notice any difference in performance and I think it’s either due to the size of the CSS file or the fact that I’m using WAMP at the moment.

I have the following questions:

1.) What type of overhead can one expect to see be reduced by using this approach?

2.) Can this same practice be applied in JavaScript files?

You’re telling the browser to always revalidate on every request.

Furthermore, you should set it to a higher amount, larger than what you have now (you have it set to 1 hour). Like 2 - 4 weeks.


$date = gmdate("D, j M Y H:i:s", time() + 60 * 60 * 24 * 30); // 30 Days from now
ob_start("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Expires: " . $data . " UTC");
header("Cache-Control: Public");
header("Pragma: Public");

You can also do this through Apache. If you’re in Apache 2.x: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

I would suggest the Apache way.

Thanks for the info, Cerium. I think I’ll follow your lead on this.