How to enable GZIP compression
There are several ways to increase a website’s speed. Enabling GZIP compression from the server is one standard practice. While GZIP is commonly known as a file format, it is also a software application responsible for reducing the size of files (HTML, stylesheets, JavaScript, etc.). It allows a server to provide compressed files to the browser for a faster network transfer. This is an easy way to optimize your website and improve user experience.
You can enable GZIP compression using two different Apache mods: mod_deflate and mod_gzip. Both allow compression from the server before files are sent to a browser. However, mod_deflate is recommended. It is more widely supported than mod_gzip. In addition, it is documented better and configured easily. If it’s dysfunctional, you can use mod_gzip. We have provided both Apache mods below for your reference.
Enable GZIP compression
Here's a detailed instruction to enable GZIP compression in the .htaccess file:
- Click Sign Up / Log In at the top of this page.
- Select Hosting Manager from the drop-down menu.
- Enter your username and password, and click Log In.
- On the Home page, click the Files icon or the [ v ] arrow symbol on its right side.
- Click on the File Manager icon next to Directory Privacy.
- In the pop-up box, make sure to choose Web Root and tick the box that says Show Hidden files (dot files).
- Click Go.
- Right-click on the .htaccess file, select Edit.
- A code editor popup will display, click Edit.
- Add one of the following scripts inside the .htaccess file:
Enable mod_deflate (recommended):
AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/opentype # For Olders Browsers Which Can't Handle Compression BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html Enable mod_gzip:
mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_include mime ^text/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* mod_gzip_item_exclude mime ^image/.* - Click Save Changes at the upper right-hand corner.
Congratulations! You have compressed your website files.