How to compress my CSS with gZIP?

To compress your CSS files with gZIP there are two things that you should do.

First, add the following line to the .htaccess file in your public_html folder:

AddHandler application/x-httpd-php52 .css

By doing this, you allow the server to process .css files through PHP.

Next, add the following lines at the very beginning of your .css file(s):

<?php
ob_start (“ob_gzhandler”);
header(“Content-type: text/css; charset: UTF-8”);
header(“Cache-Control: must-revalidate”);
$offset = 60 * 60 ;
$ExpStr = “Expires: ” .
gmdate(“D, d M Y H:i:s”,
time() + $offset) . ” GMT”;
header($ExpStr);
?>

By doing this, you will enable the gZIP compression for your CSS file. For bigger websites there will be a significant improvement in the loading speed of your pages.

You can check the effect using this optimization tool – http://analyze.websiteoptimization.com/

kbadmin has written 149 articles

Loading Facebook Comments ...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.