Minify or compress CSS in PHP

For developers of plugins or themes, it is important to provide the included CSS (stylesheets) files to the user in a compressed or minified version. This mainly benefits the page speed of the website and is very helpful for the search engine optimization as well as for the user experience itself.

How can I compress CSS files?

The following PHP function provides an easy way to compress CSS files without having to manually do it each time you edit a stylesheet file. A compressed file version of the original CSS file could be easily stored in a temporary folder and retrieved if the file exists. This saves a considerable amount of CSS code and reduces the file size.

How do we use the CSS Minify function?

The function minify_css( $file_content ); ensures that all unnecessary tabs, spaces, breaks, and comments in the CSS file are removed. As result, we get a compressed and minified version of the file content.

Minify or compress CSS in PHP Score: 5 / 5 (1vote)