Pregunta

Is this a good idea to serve a css file by php ?

Actually I have a large CSS file which include all media query so I thought to serve only selected section based on the argument passed to the php page Eg In my original php page I will do like this

<link rel="stylesheet" type="text/css" href="css.php?<?= "theam=".$theam ."&screen=".$screen ?>"/>

and in the css.php file I will check the condition to give response with only required css is this the correct Way ?

¿Fue útil?

Solución

Yes, it's ok as long as you add headers:

header('Content-type: text/css');

And make sure you check the $_GET for correct values

Another suggestion is changing the url to some nicer ones with rewrite:

RewriteRule ^css-(.*)-(.*)\.css$  /css.php?theam=$1&screen=$2
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top