# Enable GZIP
php_value output_handler ob_gzhandler

# Use gzip compression
<IfModule mod_gzip.c>
        mod_gzip_on       Yes
        mod_gzip_dechunk  Yes
        mod_gzip_item_include file      \.(html?|txt|css|js|php|pl|jpg|png|gif)$
        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      ^image/.*
        mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

# Handle ETag
<FilesMatch "\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt)$">
        FileETag none
</FilesMatch>

# Add headers for caching
<IfModule mod_headers.c>
    # Default: 1 Week
    Header set Cache-Control "max-age=604800, public"
    # 1 Year: ICO, PDF, FLV
    <FilesMatch "\.(ico|pdf|flv)$">
        Header set Cache-Control "max-age=29030400, public"
    </FilesMatch>
    # 1 Month: JPG, PNG, GIF, SWF
    <FilesMatch "\.(jpg|png|gif|swf)$">
        Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
    # 1 Month: XML, TXT, CSS, JS
    <FilesMatch "\.(xml|txt|css|js)$">
        Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
    # 1 Second: HTML, PHP
    <FilesMatch "\.(html|htm|php)$">
        Header set Cache-Control "max-age=1, public"
    </FilesMatch>
</IfModule>

# Expire handler
<IfModule mod_expires.c>
    # Enable expirations.
    ExpiresActive On
    # Cache all files for 1 week
    ExpiresDefault A604800
    # 1 Year: ICO, PDF, FLV
    <FilesMatch "\.(ico|pdf|flv)$">
        ExpiresDefault A31449600
    </FilesMatch>
    # 1 Month: JPG, PNG, GIF, SWF
    <FilesMatch "\.(jpg|png|gif|swf)$">
        ExpiresDefault A2592000
    </FilesMatch>
    # 1 Month: XML, TXT, CSS, JS
    <FilesMatch "\.(xml|txt|css|js)$">
        ExpiresDefault A604800
    </FilesMatch>
    # 1 Second: HTML, PHP
    <FilesMatch "\.(html|htm|php)$">
        ExpiresDefault A1
    </FilesMatch>
</IfModule>