Web :: General :: dynamic stylesheets caching ? Les pages de style dynamiques sont-elles en cache ? |
|||
| By: Josdeveld |
Date: 26/04/2006 09:35:34 |
Points: 20 | Status: Answered Quality : Excellent |
|
Hello, désolé d'écrire en anglais mais il est bien meilleur que mon français. I'm using a server-side script language (namely, PHP) to generate my stylesheets , using : 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 on the client? Will they be cached as well as regular, static, ".css" stylesheets? I found that regular stylesheets are cached for a long period of time by the browsers and that is what I'm aiming for using my dynamic stylesheets. As a side question, would the the stylesheet's URI ending with ".php" (+ some parameters) amper the browser to cache its contents ? Or will it obey the Content-type only ? Thanks in advance |
|||
| By: VGR | Date: 26/04/2006 09:54:00 | Type : Answer |
|
| Hello, First for all readers they have to know that in order to be able to do that, you need to apply one of those two well-known techniques : 1a) use SSI on the CSS (server-side includes), like in : <link rel="stylesheet" href="styles.php?someparam=somevalue" type="text/css"> Just make sure it outputs it with the correct mime type in the headers: text/css 1b) use a server-side script to generate (ASP,PHP,etc) : Code like you did, using parameters to the css.php URI so that $_GET[] is available in the css script. You will also need to modify the AddType settings in the Apache httpd.conf file (or the IIS equivalent, if there is one ;-) AddType application/x-httpd-php .css Now, as for your main question : AFAIK, dynamically generated stylesheets are exactly like other PHP-generated pages, ie they are not to be cached by default - you must use the PHP header function to set a cache setting, like in this adapted php.net example : <?php Header('Cache-Control: must-revalidate'); $offset = 60 * 60 * 24 * +1; //VGR REM expires tomorrow Header('Expires: '.gmdate('D, d M Y H:i:s',time()+$offset).' GMT'); ?> The fast answer to your side question are "no" and "yes under conditions" (ie, for a decent browser) best regards |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








