Mod_deflate.c – compress webpages and files
Version: 43.1
Revision: 13 Build 11
Mod_deflate.c – compress webpages and files
Introduction: from my previous article I was writing a big tutorial on “Gzip” compression for Apache v1.3xx or higher.
But, this time there is going to be an article about: “mod_deflate.c” which is designed for Apache v2.0xx or higher…
Notes: older browser might have problems with “mod_deflate” compression.
But, these browsers: “IE5, IE6, IE7, Opera 8 & 9, Safari, Camino & FF1 & FF2” will not be affected!
1.] Download notepad++ from the original author or from a mirror and install the software.
——————————-
http://sourceforge.net/projects/notepad-plus/
http://filehippo.com/download_notepad/
——————————-
2.] Copy one of these codes and insert at the very top of the “.htaccess” file.
However, please delete your old “.htaccess” files before uploading…
a.] match a certain type of files or extension and compress (v1).
—Copy Source Code—
<IfModule mod_deflate.c> <FilesMatch "\\.(js|css|html|htm|php|xml)$"> SetOutputFilter DEFLATE </FilesMatch> </IfModule>
—End Source Code—
b.] deflate individual files (manually) and exclude the rest…
—Copy Source Code—
<IfModule mod_deflate.c> <Location /> # Files and Text to compress #*************************** AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css 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 application/x-httpd-php AddOutputFilterByType DEFLATE application/x-httpd-fastphp AddOutputFilterByType DEFLATE application/x-httpd-eruby # Files and Text to exclude from compression #*************************** SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary </Location> </IfModule>
—End Source Code—
Notes: please remove the ones which you don’t need or require.
c.] compress a specific directory…
—Copy Source Code—
<IfModule mod_deflate.c> <Directory "/static/help"> AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css </Directory> </IfModule>
—End Source Code—
e.] using “mod_deflate.c” and disable buggy browser from compressing data.
—Copy Source Code—
<IfModule mod_deflate.c> # Compress contents that of a certain type AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-httpd-php AddOutputFilterByType DEFLATE application/x-httpd-fastphp AddOutputFilterByType DEFLATE application/x-httpd-eruby AddOutputFilterByType DEFLATE text/html # Files and Text to exclude from compression #*************************** SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary # Properly handle old browsers that doesn't support compression BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html </IfModule>
—End Source Code—
f.] compress all types of extension and exclude the rest (v2).
—Copy Source Code—
<IfModule mod_deflate.c>
<Location />
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \\.(?:exe|t?gz|zip|gz2|sit|rar)$ no-gzip dont-vary
</Location>
</IfModule>
—End Source Code—
e.] Compress everything with “DeflateFilterNote”. However, this is optional…
—Copy Source Code—
<IfModule mod_deflate.c> SetOutputFilter DEFLATE DeflateFilterNote ratio SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary </IfModule>
—End Source Code—
f.] Deflate everything with browser support (mostly for older browser).
—Copy Source Code—
<IfModule mod_deflate.c> SetOutputFilter DEFLATE SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html </IfModule>
—End Source Code—
g.] This is one of my version, which I was using from my old server (from stonerocket) and it was a very well built version. However, there two big setback…
————————————————–
1.] To allow compression from a proxy client, you’ll need to install “mod_headers.so”.
Without this “mod_engine.so”, there might be some errors and conflicts if you’re behinde a proxy server!
2.] You’ll need to remove some parts and stitch them up by pieces.
Nevertheless, if you don’t know, please use the above codes…
—Copy Source Code—
# Version: 31
# Apache Version: 2.1xxx
#*******************************
# Method 1 - Only compress specified content type
<Location />
<IfModule mod_deflate.c>
# compress content with type html, text, and css
AddOutputFilterByType DEFLATE text/html text/plain text/css
<IfModule mod_headers.c>
# properly handle requests coming from behind proxies
Header append Vary User-Agent
</IfModule>
</IfModule>
</Location>
# Method 2 - Compress all content, manually excluding specified file types
<IfModule mod_deflate.c>
# place filter 'DEFLATE' on all outgoing content
SetOutputFilter DEFLATE
# exclude uncompressible content via file type
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip)$ no-gzip dont-vary
<IfModule mod_headers.c>
# properly handle requests coming from behind proxies
Header append Vary User-Agent
</IfModule>
</IfModule>
# deflate.log.
# log compression ratio on each request
<IfModule mod_deflate.c>
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate.log deflate
</IfModule>
# Properly handle old browsers that do not support compression
<IfModule mod_deflate.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
—End Source Code—
h.] This is my final version.
Well…its just a little bonus for the readers and code hookers!
Notes: this “htaccess” script has browser support (for older browser), Log format and deflate compression level.
DeflateCompressionLevel 1
Warning: setting your “compression level + memory level” from 1 to 9, this could destroy your data, triggers errors and accessive bandwidth. So, please consider your compression level before you continue.
—Copy Source Code—
# Version: 45.1 [Final]
# mod_deflate engine
#*****************************
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
DeflateCompressionLevel 9
DeflateMemlevel 9
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
</IfModule>
—End Source Code—
i.] This version was created for advance users. However, please be careful about the compression level. They can also eat up your server’s memory and CPU usage!
—Copy Source Code—
<IfModule mod_deflate.c> SetOutputFilter DEFLATE DeflateFilterNote ratio DeflateCompressionLevel 9 DeflateMemlevel 9 DeflateWindowSize 15 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar|Z)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary </IfModule>
—End Source Code—
3.] Save your “htaccess” file and upload it to your server.
But, don’t forget to delete the old version before uploading!!
4.] Done!
Notes: please check your website if you have compression enabled…
http://www.seoconsultants.com/tools/compression.asp
Tips: if you’re getting an error, please try this method…
—Copy Source Code—
<Location /> <IfModule mod_deflate.c> SetOutputFilter DEFLATE DeflateFilterNote ratio DeflateCompressionLevel 9 DeflateMemlevel 9 DeflateWindowSize 15 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar|Z)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary </IfModule> </Location>
—End Source Code—
Copyrighted by Lair360
?>/images/ads_logo.jpg)
