To save a bit of bandwidth and score higher on search engine optimization reports, enable gzip compression for text based files. Remember, images and videos do not compress and will only waste your server’s CPU.
Place this code in your .htaccess file.
WARNING: Make a backup of your htaccess file first so you can revert to your working file in the event something goes wrong.
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
# Or, compress certain file types by extension:
SetOutputFilter DEFLATE
Related blog, client side caching.