My CSS file is a PHP file that is served with the text/css content type, so I can use PHP variables in this file. style.php as follows:
<?php header('Content-Type: text/css'); $bgColor = '#000'; ?> body { background:<?php print $bgColor; ?>; }
It works as expected, but I'm a little worried if the browser caches a dynamically generated css file.
When viewing requests in firebug, it seems to me that the browser style.php again every time I reload the page.
I already tried to add these cache headers:
header('Cache-control: must-revalidate'); header('Expires: ' . gmdate('D, d MYH:i:s', time() + 60 * 60 * 24) . ' GMT');
But no luck. A file is downloaded every time the page loads. What are the appropriate headers to make the browser cache the file for a certain amount of time?
css php caching dynamic header
Max
source share