What is Gzip Compression?
When a user visits your website, the files from the server end are requested by the client’s browser. The server compresses the files and thus reduces the transfer time. On the client’s side the file is first decompressed and then visualized.
Why is it important?
It is recommended because of the reasons below;
- Sometimes the file size is reduced to 70%.
- It increases the page speed.
- Cost benefit ratio: high
Enable Compression using htaccess
Compression can be enabled by adding code below to a file named .htaccess on web host/server.
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
Enable Compression on Apache Web Servers
If the above does not work try using below code:
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
Enable Compression on NGINX
Add the below code to the config file
gzip on;gzip_comp_level 2;
gzip_buffers 16 8k;
# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";
# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
Enable Compression on IIS
If your are using IIS server, we recommend you to check out Microsoft’s guide:
Do you find this tutorial useful? If yes, you will certainly love our support. OXO Solution hosting plan includes 24/7 support from our experienced developers.
Check out our plans.