In this post I will demonstrate how to compress text content in your web applications or websites, so that your trafficked size is smaller and therefore your application load time as well.
To do this, we will use the Apache web server configuration file, the .htaccess. Remember that files such as videos, music, and other binary files are probably already compressed, and because they are usually much larger than text files, would require a lot of server processing to compress them again, and the gain from compression would be Minimum.
Enabling compression with DEFLATE
This is the easiest compression to configure on the server and is already enabled by default. It uses less server processing than GZip, but does not compress as much as it does.
# Compactar por tipo - html, text, css, xml
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
# Compactar por extensão
AddOutputFilter DEFLATE js css htm html xml ttf eot
Enabling Compression with GZip
GZip has been gaining a lot of space on the web today because of its great data compression power, reducing page load times dramatically, especially when we talk about mobile internet (3G) in Brazil, which is still very slow and precarious Many places. Because it has a high level of compression, it requires more processing than the DEFLATE compression method.
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|ttf|eot)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*