How to Enable Gzip Compression On Your Web Server
What is Gzip Compression?
Gzip is a file format and is a method of compressing files to make faster network transfer. Gzip performs best on text-based content and can compress 50%~80% for larger files. Enabling Gzip compression makes your website performance better and save the network bandwidth. In this article, I will show you how to enable Gzip compression on your web server.
Enable Gzip Compression on Apache Web Server
Copy and paste the following code in your .htaccess file and save. Your .htacess file locates in the root of domain.
## BEGIN Enable GZIP Compression ##
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
SetOutputFilter DEFLATE
</IfModule>
## END Enable GZIP Compression ##
Enable Gzip Compression on Nginx Web Server
If you are running web server with Nginx, edit your nginx.conf file. Copy and paste the following code.
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
After enabling Gzip compression configuration on your web server, test with Gzip compression tools. The following picture is my website’s Gzip compression status report.
According to the report, Gzip is enabled on newbiesbox.com and compression ratio is 86.37% of original size. If you are trying to make better performance for your website, you should make not only Gzip compression but also leverage browser caching. Cheers… :D