in , ,

Compress CSS with PHP and Optimize Website Performance.


Most of the web masters face the problem of high load time of the website. If your website takes time on loading on users browser, you need to think about it. Because most of the internet users do not want to wait extra for a website to load on browser. User use to switch to another website in this case. It can be a loss of your internet business.

Compress CSS with PHPMost common reasons which slow down the website performance are high size of CSS files and JavaScript files, images and other high size graphical content. But css and js will mostly be included in almost all the pages of any dynamic website, So it affect almost very page of your website.

Speeding up your website can be done by reducing number of css and js files, removing heavy plugins optimizing website images and reducing the size of your cs files. We can reduce the filesize of a CSS file by a very considerable ratio by removing unnecessary white spaces, comments, also making a bit modifications in the code.

CSS file compression is also a nice way to improve the website speed. By minimizing the external file sizes which also take time in loading. In general we use some external scripts to compress the CSS files. But in this tutorial i will show you how to compress Compress CSS with PHP.

1. You can compress your CSS files with PHP. But you need to save it as PHP file. Write this PHP code just before the style.php file

Attach this file to your page as

2. If you do not want to create stylesheet as a php file, you can follow the htaccess way. Create a PHP file gzip-css.php with following code.

Now add these htaccess rules in .htaccess file.

Whenever http request for .css file will come to the web server, it will be converted to application/x-httpd-php. Then gzip-css.php will be prepend to this request to compress the output of the css file.



Written by Deepanker

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Leave a Reply

Your email address will not be published. Required fields are marked *


Free font airplane

10 beautiful Free Fonts For Your Web Design


Lightbox effect with CSS