Optimized .htaccess???

Posted by StackOverflowNewbie on Stack Overflow See other posts from Stack Overflow or by StackOverflowNewbie
Published on 2010-04-28T07:05:09Z Indexed on 2010/04/28 7:13 UTC
Read the original article Hit count: 555

Filed under:
|
|
|

I'd appreciate some feedback on the compression and caching configuration below. Trying to come up with a general purpose, optimized compression and caching configuration. If possible:

  1. Note your PageSpeed and YSlow grades
  2. Add configuration to your .htaccess
  3. Clear your cache
  4. Note your PageSpeed and YSlow grades to see if there are any improvements (or degradations)

NOTE: Make sure you have appropriate modules loaded.

Any feedback is much appreciated. Thanks.

# JavaScript MIME type issues:
#   1. Apache uses "application/javascript": http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types  
#   2. IIS uses "application/x-javascript": http://technet.microsoft.com/en-us/library/bb742440.aspx
#   3. SVG specification says it is text/ecmascript: http://www.w3.org/TR/2001/REC-SVG-20010904/script.html#ScriptElement
#   4. HTML specification says it is text/javascript: http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.2.2
#   5. "text/ecmascript" and "text/javascript" are considered obsolete: http://www.rfc-editor.org/rfc/rfc4329.txt

#-------------------------------------------------------------------------------
# Compression
#-------------------------------------------------------------------------------
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml

    # The following MIME types are in the process of registration
    AddOutputFilterByType DEFLATE application/xslt+xml
    AddOutputFilterByType DEFLATE image/svg+xml

    # The following MIME types are NOT registered
    AddOutputFilterByType DEFLATE application/mathml+xml
    AddOutputFilterByType DEFLATE application/rss+xml  

    # Deal with JavaScript MIME type issues
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE text/ecmascript
    AddOutputFilterByType DEFLATE text/javascript
</IfModule>

#-------------------------------------------------------------------------------
# Expires header
#-------------------------------------------------------------------------------
<IfModule mod_expires.c>
    # 1. Set Expires to a minimum of 1 month, and preferably up to 1 year, in the future
    #     (but not more than 1 year as that would violate the RFC guidelines)
    # 2. Use "Expires" over "Cache-Control: max-age" because it is more widely accepted
    ExpiresActive on
    ExpiresByType application/pdf "access plus 1 year"
    ExpiresByType application/x-shockwave-flash "access plus 1 year"   
    ExpiresByType image/bmp "access plus 1 year" 
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/tiff "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType video/x-flv "access plus 1 year"

    # Deal with JavaScript MIME type issues
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/x-javascript "access plus 1 year"
    ExpiresByType text/ecmascript "access plus 1 year"
    ExpiresByType text/javascript "access plus 1 year"

    # Probably better to explicitly declare MIME types than to have a blanket rule for expiration
    # Uncomment below if you disagree 
    #ExpiresDefault "access plus 1 year"       
</IfModule>

#-------------------------------------------------------------------------------
# Caching
#-------------------------------------------------------------------------------
<IfModule mod_headers.c>
  <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
    Header add Cache-Control "public"
    Header unset ETag
    Header unset Last-Modified       
    FileETag none   
  </FilesMatch>
</IfModule>

© Stack Overflow or respective owner

Related posts about .htaccess

Related posts about caching