4

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 ?

1 Answer 1

7

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
Sign up to request clarification or add additional context in comments.

5 Comments

yes i know that but is it a correct way of doing it don't you think it will increase the response time for the css resource
Maybe by few microseconds until the script is executed, but that is not a problem. There is also a response time for fetching a single css. And it's WAY better if you don't include all css.
Concerning response time : you should probably use client side caching so that browsers only download each variation once sitepoint.com/caching-php-performance
thanks may be that few microseconds doesn't slow down the site as much as than loading time for the extra content
Exactly what I said, it's the best way in my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.