Gzip CSS files in PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.