In this article, I will explain how to enable GZIP compression. GZIP compression will help us to improve the site speed by compressing the site content before it serving to visitor’s browser. If your site page size is 100kb or more, then GZIP compression is the great option to improve the performance. It also helps to reduce bandwidth usage, thereby reducing HTTP response.
You can enable GZIP compression by two methods.
- By directly adding rules to .htaccess file present under your site document root
## enable apache served files compression
# We check for the module just in case
# Insert filter on selected content types only
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0 no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
You can adjust which file types are compressed by modifying “deflate” command. Some examples:-
or to compress everything except images
#Insert filter on all content
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
2. You can enable directly from cPanel.
Login to cPanel -> Software -> Optimize website
Optimize website in cPanel X3 theme.
Optimize website in cPanel paper_lantern theme.