sexta-feira, 10 de setembro de 2010

Apache mod_deflate


O módulo mod_deflate provê um filtro de deflate que permite que a saída do Apache seja comprimida antes de ser enviada para os clientes (navegadores), resultando em velocidade e economia de recursos.

Abaixo, um exemplo, onde apenas as imagens são dispensadas das regras de compactação:

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so

#DEFLATE
<IfModule mod_deflate.c>
#REGRAS
AddType text/css css gz
AddEncoding gzip gz
AddType text/javascript js jgz
AddEncoding gzip jgz
RewriteEngine on
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !.*^Mozilla/4.* [OR]
RewriteCond %{HTTP_USER_AGENT} .*MSI?E.*
RewriteRule ^(.*)concated.min.css $1concated.min.css.gz
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !.*^Mozilla/4.* [OR]
RewriteCond %{HTTP_USER_AGENT} .*MSI?E.*
RewriteRule ^(.*)concated.min.js $1concated.min.js.jgz
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css
#Compatibilidade com o Netscape 4.x
BrowserMatch ^Mozilla/4 no-gzip
#Compatibilidade como o IE
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
#Compatibilidade com o Proxy
Header append Vary User-Agent env=!dont-vary
#LOG
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog /var/log/mod_deflate.log deflate
</IfModule>

Obs.: Basta colocar as linhas acima no seu httpd.conf.



=========English version=========

The mod_deflate module provides the DEFLATE output filter that allows output from Apache to be compressed before being sent to clients (web browsers), resulting in speed and resources saving.

Below, an example, where the image doesn't where only the images are exempt from the rules of compression:

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so

#DEFLATE
<IfModule mod_deflate.c>
#RULES
AddType text/css css gz
AddEncoding gzip gz
AddType text/javascript js jgz
AddEncoding gzip jgz
RewriteEngine on
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !.*^Mozilla/4.* [OR]
RewriteCond %{HTTP_USER_AGENT} .*MSI?E.*
RewriteRule ^(.*)concated.min.css $1concated.min.css.gz
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !.*^Mozilla/4.* [OR]
RewriteCond %{HTTP_USER_AGENT} .*MSI?E.*
RewriteRule ^(.*)concated.min.js $1concated.min.js.jgz
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css
#Netscape 4.x Compatibility
BrowserMatch ^Mozilla/4 no-gzip
#IE Compatibility
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
#Proxy Compatibility
Header append Vary User-Agent env=!dont-vary
#LOG
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog /var/log/mod_deflate.log deflate
</IfModule>

PS.: Just put the lines above in your httpd.conf.

Nenhum comentário:

Postar um comentário