WordPress Code Snippets

A fresh mix of code snippets and tutorials

Compress CSS and JavaScript with PHP

131

Quick snippets for compressing CSS and JavaScript with PHP’s ob_gzhandler, which will gzip or deflate content depending on browser support.

Compress CSS content

To compress CSS content, add the following code to any PHP file (i.e., .php extension):

Compress JavaScript content

That’s all there is to it, and to further reduce file size, you should run the actual CSS/JavaScript code through the minifier of your choice.

For more information about either of these methods, check out my articles at Perishable Press: