WordPress Code Snippets

A fresh mix of code snippets and tutorials

.htaccess enable compression


Two quick code snippets for compressing your file output with Apache’s mod_deflate. Compressing your content is a great way to improve performance by decreasing the amount of data that is sent to the client.

To compress all of the file types included in the following code, add the snippet to your site’s root .htaccess file:

<IfModule mod_deflate.c>
	AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json

Feel free to add more file types or remove any that are not required or not in use.

Alternate version

Here is an alternate version that is better suited if your site needs to accommodate older browsers (like if you’re working on a company Intranet or similar):

<IfModule mod_deflate.c>
	AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
	BrowserMatch ^Mozilla/4 gzip-only-text/html
	BrowserMatch ^Mozilla/4.0[678] no-gzip
	BrowserMatch bMSIE !no-gzip !gzip-only-text/html

As before, you can add/edit/remove any file types as needed. The code itself enables compression for the specified files unless the browser is older Firefox or IE. Good times.

Further Reading

Learn more

.htaccess made easy

Show Support

Like our new Facebook Page to show support!