Forum Moderators: open
html:
<style type="text/css">@import url("css.php?css=normal&lang=en");</style>
css.php:
<?php
header('Content-type: text/css');
header('Cache-control: private') ;
header('Pragma: private');
?>
body{...}
h1{...}
etc
Do you think this kind of dynamic stylesheet will be cached efficiently on the client? Will they be cached as well as regular, static, ".css" stylesheets?
I ask that because regular stylesheets are cached for a long period of time by the browsers and that's what I want for mine too.
Does the fact that the stylesheet's path ends with ".php" (+ some parameters) will remove that extra caching behavior or do the browsers only look at the Content-type?
expires header: <?php
header("Cache-Control: must-revalidate");
$offset = 60 * 60 * 24 * -1;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($ExpStr);
?> (example from php.net for caching for one day.)
A related thread is here:
[webmasterworld.com...]
normally (as with the flip in the expires example), you want to disable the cache not enable. with the provided headers at the top (per default php might add headers to prevent caching), there should be no problem. it's not the querystring which is disabling the browser cache, these are the headers (if this file is not cached anyways!).
the expires one provides a hint to the client when a request "should" be done again. so this is a kind of add-on to a normal request of css file. in other words: i doubt that even that header is necessary and suggest to remove the cache-related header commands as well.
just compare the headers of a css file and a php file with each other to checkout and maybe eliminate the difference. after that, you browser can not even guess a difference between the css file and the php file.
--hakre