Apache servers have already integrated the GZIP compression program and you just have to enable it. With the htaccess this is quickly done in a few steps and your GZIP is activated. The advantage is that you get compressed files delivered faster. There are many ways to do that, but here I would like to introduce the htaccess variant.
Enable GZIP with the htaccess
For us, the DEFLATE (algorithm) is important in the first place that is GZIP encoding of two parts (LZ77 and Huffman-coding), here we can use an AddOutputFilterByType for all applications to compress them in the output. And that could look like this. You can enable the GZIP module in the Apache configuration file, but it should already be enabled. Call configuration file in the console (Terminal)
USERNAME$ nano /etc/httpd/conf/httpd.conf
# LoadModule deflate_module modules/mod_deflate.so
LoadModule deflate_module modules/mod_deflate.so
# MBT BEGIN GZIP
# Set DEFLATE filter
# Compress on output
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/json
AddOutputFilterByType DEFLATE text/vtt
AddOutputFilterByType DEFLATE text/php
AddOutputFilterByType DEFLATE text/x-component
AddOutputFilterByType DEFLATE application/js
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/ld+json
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/icon
AddOutputFilterByType DEFLATE image/ico
AddOutputFilterByType DEFLATE image/jpeg
AddOutputFilterByType DEFLATE image/jpg
AddOutputFilterByType DEFLATE image/gif
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent
# MBT END GZIP
You can also place these lines at the end of your configuration file or in the htaccess. Thus, we have included almost all file types to compress them in the output via GZIP. Below you will also find a tool to check whether the compression is now effective, s.besten you test it first without and then with. I'm 100% sure that it works and you'll get better results with Google Page Speed ;).
Set and use browser cache
Now that you have activated the GZIP, we can set the expiration date for our applications and use the browser cache. This brings us another small advantage in terms of speed and we are rated better.
# MBT BEGIN BROWSERCACHE
# Pictures and other resources can be generously cached HTML rather not
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 60 seconds"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/xml "access plus 60 seconds"
ExpiresByType application/json "access plus 60 seconds"
ExpiresByType application/rss+xml "access plus 60 seconds"
ExpiresByType application/atom+xml "access plus 60 seconds"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/icon "access plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
# MBT END BROWSERCACHE
Now we have applied the full range of browser cache, I have always driven well with these settings and therefore not really screwed, although I think that you can get even more out. So if you have an idea or even a concrete solution always happy with it.
If you use WordPress then put both code snippets over the WordPress code snippet.
Testing GZIP compression
Have you added everything in your htaccess so you can now also test whether everything really grabs and something is compressed. Here you can see how much it is when it is compressed and how much if it was not compressed and much more.
Well, if your GZIP is working now, what 99% of these two above solutions should apply to, because I'm pretty sure it will work for anyone who uses it. Then you did it and successfully activated your GZIP.