← Back to team overview

exponent-cms team mailing list archive

Improve client side caching

 

I've run come across a bit of .htaccess code that really improves
client-side caching. It can really improve the YSlow score and I think it
would be a nice complement to the server side cacheing we already have
courtesy of Smarty. The problem is .htaccess scripting is one of my
weaknesses. So I thought I'd see if any other developers might be able to
integrate the below script with the existing .htaccess file without messing
things up J

 

# 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>

 

 

 

Jonathan Worent

President

 

Inspired Bytes

 <http://www.inspiredbytes.net> www.inspiredbytes.net

 <mailto:jonathan@xxxxxxxxxxxxxxxxx> jonathan@xxxxxxxxxxxxxxxxx

(309) 645-5416

 

6500 N University St

Suite 301

Peoria, IL 61614

 

 

--------------------------------------------

Privilege and Confidentiality Notice
The information in this transmission is intended only for the named
recipient(s).  It may contain information that is privileged, confidential,
and is exempt from disclosure under applicable laws. Any use, dissemination
or distribution of this transmission is strictly prohibited.  If this
transmission was received in error please destroy all copies of this
transmission, and notify the sender immediately.