문제

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 ?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top