visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
294 experts, 1172 registered users, 1625 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


The DDRK link is back online.
We got a one week service interruption, sorry.
(23-30/01/2010)

Web :: General :: dynamic stylesheets caching ? Les pages de style dynamiques sont-elles en cache ?


By: Josdeveld Belgium  Date: 26/04/2006 09:35:34  French English  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 English  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

 Add This Article To:
 del.icio.usDel.icio.us  diggDigg  googleGoogle  spurlSpurl
 blinkBlink  wongWong  simpySimpy  yahooY! MyWeb 
EContact
browser fav
page generated in 59.274200 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page