CSS Combine and Compress


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

Combine multiple css files into 1 file that has been stripped of whitespace and comments.


Copy this code and paste it in your HTML
  1. <?php
  2. header('Content-type: text/css');
  3. ob_start("compress");
  4. function compress($buffer) {
  5. /* remove comments */
  6. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  7. /* remove tabs, spaces, newlines, etc. */
  8. $buffer = str_replace(array("
  9. ", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
  10. return $buffer;
  11. }
  12.  
  13. /* your css files */
  14. include('master.css');
  15. include('typography.css');
  16. include('grid.css');
  17. include('print.css');
  18. include('handheld.css');
  19.  
  20. ?>

URL: http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.