Good tip to drastically decrease size of CSS file...

Discussion in 'CSS' started by Divisive Cottonwood, Jun 5, 2008.

  1. #1
    I haven't read this on here before so I post it up in the hope that it is new information for you...

    As you know, CSS files can get mighty beasts... here's a good tip to shrink them and leave faster loading files for your user...

    Make a PHP file with the following at the top:

    <?php if(extension_loaded('zlib')){ob_start('ob_gzhandler');} header("Content-type: text/css"); ?>
    Code (markup):
    Then place your CSS inbetween...

    And at the bottom of the CSS place this:

    <?php if(extension_loaded('zlib')){ob_end_flush();}?>
    Code (markup):
    Now in the head of your html document point to the php file instead of the css.

    For instance, it may read mydesign.css - now it will read mydesign.php...

    Got it?!

    So your swapping the CSS file for PHP one, but with the CSS information in it...

    I use it in this website here and it works a treat.

    Slow dial up connections might not be a problem these days, but javascript-heavy web 2.0 sites are... this will help reduce the size of your load time...
     
    Divisive Cottonwood, Jun 5, 2008 IP