Posted By

iTony on 06/09/09


Tagged

css php gzip performance compression


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

Nanobyte
vali29
jealousy
BrianCoyDesign
userpiv
bodito


Gzip CSS files in PHP


 / Published in: PHP
 

URL: http://www.ethanandjamie.com/blog/43-web-dev-freebies/85-php-gzip-css-files

  1. <?php
  2. if(extension_loaded('zlib')){
  3. ob_start('ob_gzhandler');
  4. }
  5. header ("content-type: text/css; charset: UTF-8");
  6. header ("cache-control: must-revalidate");
  7. $offset = 60 * 60;
  8. $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
  9. header ($expire);
  10. ob_start("compress");
  11. function compress($buffer) {
  12. // remove comments
  13. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  14. return $buffer;
  15. }
  16.  
  17. // list CSS files to be included
  18. include('baseline.css');
  19. include('styles.css');
  20.  
  21. if(extension_loaded('zlib')){
  22. }
  23. ?>

Report this snippet  

You need to login to post a comment.