How to enable GZIP output compression in WordPress

WordPress Snippets

There are a few ways to enable GZIP output compression in WordPress:

Alternative 1: Edit your .htaccess file: You can add the following code to your .htaccess file to enable GZIP compression:

// Enable GZIP output compression
// More snippets at wpunplugged.com 

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
</IfModule>

Alternative 2: You can also enable GZIP compression by adding the following line of code to your functions.php file:

// Enable GZIP output compression
// More snippets at wpunplugged.com 

ob_start('ob_gzhandler');

Share this post

You might also like...

Forum

bbPress for WordPress Review

bbPress is a great plugin for WordPress that offers a powerful forum solution for WordPress websites. It is well-supported, easy to use, and provides great

Read More »

Comment

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