Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining multiple CSS files

Tags:

css

php

Right now I use a PHP script to pull together multiple CSS files into one script and then output them with a content-type of text/css.

The problem them with this is the browser wont cache the file.

Is there a better way of doing this?

Thanks

like image 227
christophmccann Avatar asked Dec 13 '25 07:12

christophmccann


1 Answers

If you have to serve the CSS via PHP, you can force a cache header to be emitted, so the browser can cache the output if it so desires:

<?php

    header('Cache-control: max-age=3600'); // cache for at least 1 hour
    header('Content-type: text/css');

    readfile('css1.css');
    readfile('css2.css');
    etc...
like image 180
Marc B Avatar answered Dec 14 '25 21:12

Marc B