Gzip – compress webpages and files

Version: 43.1
Revision: 13 Build 11

Gzip – compress webpages and files

Introduction:
when I was writing another article, I was thinking about a small box that could fit many things inside without force. So, I decided to write a big article that will enable you to compress your html, php, css and javascript files without looking at a book! However, you’ll need make sure that you have “mod_gzip.c” enabled by your server provider, if not, you’ll need to notify them or ask them if “Gzip.c” was enabled.

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.] Compress a certain file type – extension.
—Copy Source Code—

<IfModule mod_gzip.c>
<Files *.html>
    SetOutputFilter DEFLATE
</Files>
</IfModule>

—End Source Code—

b.] Compress multiple type of contents.

Notes: the lines: “no-gzip dont-vary” was added to exclude certain types of files.
This is useful if you don’t want a particular file to be compress…
—Copy Source Code—

<IfModule mod_gzip.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—

c.] Compress certain types of extension in one slot.
—Copy Source Code—

<IfModule mod_gzip.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
<FilesMatch "\\.(js|css|html|htm|xml)$">
    SetOutputFilter DEFLATE
	</FilesMatch>
</IfModule>

—End Source Code—

d.] This script is for older apache model (version: 1.3xx).
—Copy Source Code—

# GZIP FOR APACHE 1.3.x SERVERS
<IfModule mod_gzip.c>
mod_gzip_on       Yes
mod_gzip_dechunk  Yes
    mod_gzip_item_include file \.htm$
    mod_gzip_item_include file \.html$
    mod_gzip_item_include file \.php$
    mod_gzip_item_include file \.txt$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include file \.js$
    mod_gzip_item_include file \.css$
    mod_gzip_item_include file \.rdf$
    mod_gzip_item_include file \.xml$
    mod_gzip_item_include file \.rss$
    mod_gzip_item_include mime ^application/x-httpd-php
    mod_gzip_item_include mime ^application/x-javascript
    mod_gzip_item_include mime ^application/javascript
    mod_gzip_item_include mime ^text/css$
    mod_gzip_item_include mime ^text/plain$
    mod_gzip_item_include mime ^text/xml$
	mod_gzip_item_exclude mime      ^image/.*
	mod_gzip_item_exclude file \.flv$
	mod_gzip_item_exclude file \.pdf$

</IfModule>

—End Source Code—

e.] this is a portable version and it compress files that ends with a specific extension.
—Copy Source Code—

<IfModule mod_gzip.c>
  <FilesMatch "\.(css|js|x?html?)$">
	SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>

—End Source Code—

f.] This is another alternative and it does work.
But, this time, the compression engine will support older browser!
—Copy Source Code—

<Ifmodel mod_gzip.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>
# Deactivate compression for buggy browsers
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 my last version which includes “cgi-script” and exclude”rspheader” for the compression engine.
—Copy Source Code—

<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|ini)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime     ^application/xml
    mod_gzip_item_exclude mime     ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

—End Source Code—

e.] This is my own favorite. But, guess what?
It works!
—Copy Source Code—

<IfModule mod_gzip.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—

Notes: if you want to modify your compression level, just add this code.
But, the maximum level – compression is 9.
—Copy Source Code—

DeflateCompressionLevel 3

—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: if you want to check your Apache’s information and installed module, then, please use this code…
—Copy Source Code—

<?php
phpinfo();
?>

—End Source Code—

Copyrighted by Lair360

Comments are closed.