Speed up your website and use gzip compression using the .htaccess file in the root of your website’s directory if you are using Apache or NGIX (Linux).
You can actually use two different Apache mods to enable HTTP gzip compression: mod_gzip and mod_deflate. Mod_gzip enables gzip compression and mod_deflate makes it possible to compress the output from your server before it is being sent to your visitor it is the same thing.
Enabling gzip compression or deflate can reduce the size of the transferred response by up to 90%, which can significantly reduce the amount of time to download the resource and reduce data usage.
What deflate does is, it will compress the requested page on your server and send it to the visitor’s web browser which will decompress it, so the transfer will be much faster. Use one of the codes hereunder and add it to the .htaccess file:
You can also use this code if the first one doesn’t work, sometimes it happens it depends on the server configuration, we use the code hereunder on most of our websites. Copy and add it to your .htaccess file but never use both:
Note: you can add or remove certain file types from the above examples if you don’t or do want to use it.
We use this one
We use this code most out of the cases we added some more extensions to fit our needs (it includes xml and work on most servers) and is clean and short:
#Begin gzip and deflate <filesMatch "\.(html?|txt|css|js|php|pl|xml)$"> SetOutputFilter DEFLATE #End gzip and deflate
If you enable gzip compression the next step is: Leverage browser caching
Check this article on what to add to your .htaccess file to let the client cache your images, scripts or files so the visitor’s browser doesn’t download the same files over and over again: Enable Leverage browser caching using the .htaccess file for Apache