Compress Mltiple CSS Files

Usually when you're using different CSS files on your site, they might take a quite long to be loaded. Using this PHP code, you can compress them into a single file with no unnecessary white spaces or comments. Why we need to compress multiple CSS files? The answer is: the compressing procedure may take a less time than a total time of loading each file separately.

[View All Snippets]
Show Plain Text »
  1. <?php
  2. header('Content-type: text/css');
  3. ob_start('compress_css');
  5. function compress_css($buffer) {
  6.     /* remove comments in css file */
  7.     $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  8.     /* also remove tabs, spaces, newlines, etc. */
  9.     $buffer = str_replace(array("\r", "\n", "\r\n", "\t", '  ', '    ', '    '), '', $buffer);
  10.     return $buffer;
  11. }
  13. /* a list of your css files */
  14. include('style.css');
  15. include('css/menu.css');
  16. include('css/typography.css');
  17. include('css/print.css');
  18. include('inc/css/footer.css');
  20. ob_end_flush();
  21. ?>
Create Your Free Account
Please remember that this information is essential to use our services correctly.
After creating the account you will be able to download all of our FREE products.
Fields marked with * are mandatory

Please send me information about updates, new products, specials and discounts from ApPHP!
We recommend that your password should be at least 6 characters long and should be different from your username/email. Please use only letters of the English alphabet to enter your name.

Your e-mail address must be valid. We use e-mail for communication purposes (order notifications, etc). Therefore, it is essential to provide a valid e-mail address to be able to use our services correctly.

All your private data is confidential. We will never sell, exchange or market it in any way. Please refer to Privacy Policy.

By clicking "Create Account", you are indicating that you have read and agree to the ApPHP Terms & Conditions.

Quick Registration with: Facebook / Google